Una soluzione completamente in-memory. Sostituire le proprietà spring.*
come richiesto.
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-broker</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
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);
}
}
Aggiungi initial-config.json
come una risorsa:
{
"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\" }"
}]
}
RabbitMQ implementa AMQP 0.8; 0.9.1 e AMQP 1.0. Se stai usando un Mac, è abbastanza facile avviare/fermare rabbitmq per i tuoi test. Questo è per PHP ma potrebbe aiutarti nel tuo caso d'uso http://videlalvaro.github.io/2013/04/using-rabbitmq-in-unit-tests.html –
Ciao @old_sound, grazie per averlo esaminato. Idealmente vorrei evitare di richiedere rabbitmq sulla scatola per testare, i nostri test girano su un server CI che non possiamo installare facilmente RabbitMQ. – ahjmorton
Questo server CI ha almeno installato Erlang?Se sì, puoi solo scaricare il tarball di coniglio, decomprimerlo e avviarlo/fermarlo per i test –