This example shows you how to configure SSL with JBoss Messaging to send and receive message.
Using SSL can make your messaging applications interact with JBoss Messaging service securely. An application can be secured transparently without extra coding effort. To secure your messaging application with SSL, you need to configure connector and acceptor as follows:
<!-- Connector -->
<connector name="netty-ssl-connector">
<factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
<param key="jbm.remoting.netty.host" value="localhost" type="String"/>
<param key="jbm.remoting.netty.port" value="5500" type="Integer"/>
<param key="jbm.remoting.netty.sslenabled" value="true" type="Boolean"/>
<param key="jbm.remoting.netty.keystorepath" value="server0/jbm.example.keystore" type="String"/>
<param key="jbm.remoting.netty.keystorepassword" value="jbmexample" type="String"/>
</connector>
<!-- Acceptor -->
<acceptor name="netty-ssl-acceptor">
<factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
<param key="jbm.remoting.netty.host" value="localhost" type="String"/>
<param key="jbm.remoting.netty.port" value="5500" type="Integer"/>
<param key="jbm.remoting.netty.sslenabled" value="true" type="Boolean"/>
<param key="jbm.remoting.netty.keystorepath" value="jbm.example.keystore" type="String"/>
<param key="jbm.remoting.netty.keystorepassword" value="jbmexample" type="String"/>
<param key="jbm.remoting.netty.truststorepath" value="jbm.example.truststore" type="String"/>
<param key="jbm.remoting.netty.truststorepassword" value="jbmexample" type="String"/>
</acceptor>
In the configuration, the jbm.example.keystore is the key store file holding client certificate. The jbm.example.truststore is the file for server to hold trusted client certificates. They are pre-generated for illustration purpose.
To run the example, simply type ant
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();
}
}