Forked from mlaccetti/EmbeddedMessageQueueResource.java
Created
August 6, 2017 22:45
-
-
Save marhan/8efa0c426b2cbe1f31ab692540157b64 to your computer and use it in GitHub Desktop.
Apache QPid as embedded MQ broker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package laccetti.test; | |
import org.apache.qpid.server.Broker; | |
import org.apache.qpid.server.BrokerOptions; | |
import com.google.common.io.Files; | |
/** | |
* We shouldn't need external things for testing | |
*/ | |
public class EmbeddedQpidBroker { | |
private static final int BROKER_PORT = 5672; | |
private final Broker broker = new Broker(); | |
private final BrokerOptions brokerOptions = new BrokerOptions(); | |
public EmbeddedQpidBroker() { | |
final String configFileName = "/qpid-config.json"; | |
// prepare options | |
brokerOptions.setConfigProperty("broker.name", "embedded-broker"); | |
brokerOptions.setConfigProperty("qpid.amqp_port", String.valueOf(BROKER_PORT)); | |
brokerOptions.setConfigProperty("qpid.work_dir", Files.createTempDir().getAbsolutePath()); | |
brokerOptions.setInitialConfigurationLocation(getClass().getResource(configFileName).toString()); | |
} | |
public void start() throws Exception { | |
broker.startup(brokerOptions); | |
} | |
public void stop() { | |
broker.shutdown(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "${broker.name}", | |
"modelVersion": "6.0", | |
"authenticationproviders" : [ { | |
"name" : "plain", | |
"type" : "Plain", | |
"secureOnlyMechanisms": [], | |
"users" : [ { | |
"id" : "63189d1e-ef06-4ecf-8392-3198644de2ad", | |
"name" : "guest", | |
"type" : "managed", | |
"password" : "guest", | |
"lastUpdatedBy" : "guest", | |
"lastUpdatedTime" : 1474042203947, | |
"createdBy" : "guest", | |
"createdTime" : 1474042203947 | |
} ] | |
} ], | |
"brokerloggers" : [ { | |
"name" : "stdout", | |
"type" : "Console", | |
"brokerloginclusionrules" : [ { | |
"name" : "Root", | |
"type" : "NameAndLevel", | |
"level" : "WARN", | |
"loggerName" : "ROOT" | |
}, { | |
"name" : "Qpid", | |
"type" : "NameAndLevel", | |
"level" : "WARN", | |
"loggerName" : "org.apache.qpid.*" | |
}, { | |
"name" : "Operational", | |
"type" : "NameAndLevel", | |
"level" : "WARN", | |
"loggerName" : "qpid.message.*" | |
} ] | |
} ], | |
"ports" : [ { | |
"name" : "AMQP", | |
"port" : "${qpid.amqp_port}", | |
"authenticationProvider" : "plain", | |
"virtualhostaliases" : [ { | |
"name" : "nameAlias", | |
"type" : "nameAlias" | |
}, { | |
"name" : "defaultAlias", | |
"type" : "defaultAlias" | |
}, { | |
"name" : "hostnameAlias", | |
"type" : "hostnameAlias" | |
} ] | |
} ], | |
"virtualhostnodes" : [ { | |
"name" : "default", | |
"type" : "JSON", | |
"defaultVirtualHostNode" : "true", | |
"virtualHostInitialConfiguration" : "${qpid.initial_config_virtualhost_config}" | |
} ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment