This example shows you how to configure ActiveMQ to use the HTTP protocol as its transport layer.
ActiveMQ supports a variety of network protocols to be its underlying transport without any specific code change.
This example is taken from the queue example without any code change. By changing the configuration file, one can get ActiveMQ working with HTTP transport.
All you need to do is open the server0/hornetq-configuration.xml and enable HTTP like the following
<connector name="netty-connector">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
<param key="hornetq.remoting.netty.http-enabled" value="true" type="Boolean"/>
<param key="hornetq.remoting.netty.port" value="8080" type="Integer"/>
</connector>
<!-- Acceptors -->
<acceptor name="netty-acceptor">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
<param key="hornetq.remoting.netty.port" value="8080" type="Integer"/>
</acceptor>
To run the example, simply type mvn verify
from this directory
client-jndi.properties
file in the directory ../common/config
InitialContext initialContext = getContext();
Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(topic);
TextMessage message = session.createTextMessage("This is a text message");
messageProducer.send(message);
MessageConsumer messageConsumer = session.createConsumer(queue);
connection.start();
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
finally
block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
finally
{
if (initialContext != null)
{
initialContext.close();
}
if (connection != null)
{
connection.close();
}
}