I have an embedded ActiveMQ Artemis application that I have started using below configuration & code:
broker.xml
<?xml version='1.0'?>
<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:activemq"
xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">
<core xmlns="urn:activemq:core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq:core ">
<persistence-enabled>false</persistence-enabled>
<paging-directory>target/data/paging</paging-directory>
<bindings-directory>target/data/bindings</bindings-directory>
<journal-directory>target/data/journal</journal-directory>
<large-messages-directory>target/data/large-messages</large-messages-directory>
<acceptors>
<acceptor name="in-vm">vm://0</acceptor>
</acceptors>
<security-settings>
<security-setting match="#">
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
<permission type="createDurableQueue" roles="guest"/>
<permission type="deleteDurableQueue" roles="guest"/>
<permission type="createAddress" roles="guest"/>
<permission type="deleteAddress" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="browse" roles="guest"/>
<permission type="send" roles="guest"/>
<!-- we need this otherwise ./artemis data imp wouldn't work -->
<permission type="manage" roles="guest"/>
</security-setting>
</security-settings>
<address-settings>
...
</address-settings>
<addresses>
...
</addresses>
</core>
</configuration>
jndi.properties
java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
connectionFactory.ConnectionFactory=vm://0
Main.java
SecurityConfiguration securityConfig = new SecurityConfiguration();
securityConfig.addUser("guest", "guest");
securityConfig.addRole("guest", "guest");
securityConfig.setDefaultUser("guest");
ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfig);
// Step 2. Create and start embedded broker.
server = ActiveMQServers.newActiveMQServer("broker.xml", null, securityManager);
server.start();
I have few application that produce messages and consume messages. How do I configuration these application so that they communicate with the embedded server to produce and consume message. When I use tcp://localhost:61616
as broker URL, I am not able to connect to the embedded server. What configuration changes should I make in order to achieve what I am trying to do.
This is the only acceptor
you have:
<acceptor name="in-vm">vm://0</acceptor>
Therefore this is the only URL you can use from your clients: vm://0
.
If you want to connect to tcp://localhost:61616
then you need to configure a corresponding acceptor
, e.g.:
<acceptor name="activemq">tcp://localhost:61616</acceptor>