Forked from AlejandroRivera/EmbeddedMessageQueueResource.java
Last active
February 24, 2021 10:26
-
-
Save mlaccetti/caf7c602f1f2514f308fa3488120c5e2 to your computer and use it in GitHub Desktop.
Apache QPid as embedded MQ broker
This file contains 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 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
Hi:
thank you for this note. I found it useful. However, I get a weird error message
I tried to follow the official docs from http://qpid.apache.org/releases/qpid-broker-j-8.0.0/book/Java-Broker-Virtual-Host-Initial-Configuration.html or https://cwiki.apache.org/confluence/display/qpid/How+to+embed+Qpid+Broker-J. Also, I tried with setting
virtualHostInitialConfiguration
to the one that you have set as"virtualHostInitialConfiguration" : "${qpid.initial_config_virtualhost_config}"
. But, I still get the same error.My motive is to initialize a queue beforehand, such that I do not get "Destination not found" error.
Do you have any ideas or suggestions?
Thank you :)