Embedded AMQP Java Broker

前端 未结 5 544
無奈伤痛
無奈伤痛 2021-01-31 10:38

I am trying to create integration test for a Scala / Java application that connects to a RabbitMQ broker. To achieve this I would like an embedded broker that speaks AMQP that I

5条回答
  •  隐瞒了意图╮
    2021-01-31 11:18

    A completely in-memory solution. Replace the spring.* properties as required.

    
      org.apache.qpid
      qpid-broker
      6.1.1
      test
    
    
    public class EmbeddedBroker {
      public void start() {
        Broker broker = new Broker();
        BrokerOptions brokerOptions = new BrokerOptions();
        brokerOptions.setConfigProperty("qpid.amqp_port", environment.getProperty("spring.rabbitmq.port"));
        brokerOptions.setConfigProperty("qpid.broker.defaultPreferenceStoreAttributes", "{\"type\": \"Noop\"}");
        brokerOptions.setConfigProperty("qpid.vhost", environment.getProperty("spring.rabbitmq.virtual-host"));
        brokerOptions.setConfigurationStoreType("Memory");
        brokerOptions.setStartupLoggedToSystemOut(false);
        broker.startup(brokerOptions);
      }
    }
    

    Add initial-config.json as a resource:

    {
      "name": "Embedded Test Broker",
      "modelVersion": "6.1",
      "authenticationproviders" : [{
        "name": "password",
        "type": "Plain",
        "secureOnlyMechanisms": [],
        "users": [{"name": "guest", "password": "guest", "type": "managed"}]
      }],
      "ports": [{
        "name": "AMQP",
        "port": "${qpid.amqp_port}",
        "authenticationProvider": "password",
        "protocols": [ "AMQP_0_9_1" ],
        "transports": [ "TCP" ],
        "virtualhostaliases": [{
          "name": "${qpid.vhost}",
          "type": "nameAlias"
        }]
      }],
      "virtualhostnodes" : [{
        "name": "${qpid.vhost}",
        "type": "Memory",
        "virtualHostInitialConfiguration": "{ \"type\": \"Memory\" }"
      }]
    }
    

提交回复
热议问题