1)
Add
this in standalone-full.xml under
1.1 Change the max size bytes , default 10 MB
jms.queue.DLQ
jms.queue.ExpiryQueue
0
20971520
10
1.1 Add the below line after
tag.
2)
Add
new user for JMS through add-user.bat
X:\> add-user.bat
b
ApplicationRealm
jmsUser
password
yes
check in mgm-users.properties,
application-users.properties like below line [new user with pwd]
jmsUser=aeadcf105686eafa6afc994e86a520db
3)
Add
the below line into applicaiton-roles.properties
jmsUser=guest
3.5) Start the server
D:\EAP-6.0.0.GA\jboss-eap-6.0\bin>standalone.bat -b 192.168.7.9
-Djboss.server.default.config=standalone-full.xml
Or
D:\EAP-6.0.0.GA\jboss-eap-6.0\bin>standalone.bat -b 192.168.7.9 –c standalone-full.xml
4)
Sender1.java
/**
*
*/
package com.test;
import java.util.Hashtable;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Sender1
{
public
static void main ( String [] args )
{
try
{
Hashtable
env = new Hashtable ();
env.put ( Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory" );
env.put
( Context.PROVIDER_URL, "remote://192.168.7.9:4447" );
env.put
( Context.SECURITY_PRINCIPAL, "jmsUser" );
env.put
( Context.SECURITY_CREDENTIALS, "password" );
Context
context = new InitialContext ( env );
ConnectionFactory
cf = (ConnectionFactory) context.lookup (
"jms/RemoteConnectionFactory" );
Destination
destination = (Destination) context.lookup ( "jms/queue/test" );
Connection
connection = cf.createConnection ( "jmsUser", "password" );
Session
session = connection.createSession ( false, Session.AUTO_ACKNOWLEDGE );
Queue
queue = (javax.jms.Queue) context.lookup ( "jms/queue/test" );
TextMessage
textMessage = session.createTextMessage ();
textMessage.setText
( "hello vijay 3" );
javax.jms.MessageProducer
producer = session.createProducer ( destination );
producer.send
( textMessage );
System.out.println
( "Sending Done " );
//
Close the session and connection resources.
//
context.close();
session.close
();
connection.close
();
}
catch
( Exception ex )
{
ex.printStackTrace
();
}
}
}
5)
Add
your spring+hornetq+remote+listener application into Jboss-eap-6.0\ Standalone
\ deployments folder and change your
settings according to your remote IP in applicationContext and start the
server to receive.
For ex: D:\works\SdexSOA\MessageQueueSOA\WebContent\WEB-INF\applicationContext.xml
6)
If it
is spring, add like below in application-context.xml
For
ex:-
<bean
id="destinationMail" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate"
ref="jnditemplate" />
<property name="jndiName"
value="jms/queue/mail" />
</bean>
<bean class="org.springframework.jms.listener.SimpleMessageListenerContainer">
<property name="connectionFactory"
ref="credentialsconnectionfactory" />
<property name="destination"
ref="destinationMail" />
<property name="messageListener"
ref="receiverMail" />
</bean>
<bean id="receiverMail"
class="com.gnax.sdex.soa.service.JMSReceiverService"
/>
7)
JMSReceiverService.java
package com.gnax.sdex.soa.service;
import java.util.Date;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import
com.gnax.sdex.soa.bean.common.EmailBean;
import
com.gnax.sdex.soa.utils.ConfigManager;
import com.gnax.sdex.soa.utils.EMail;
import com.gnax.sdex.soa.utils.JMSReceiverHelper;
import com.gnax.sdex.soa.vo.PatientInfoVO;
/**
*
@author Vijay .D.R
*
@version 1.0, 11/1/2013
*
@since 1.0
*/
public class JMSReceiverService implements
MessageListener
{
public
JMSReceiverService ()
{
}
public
void onMessage ( Message message )
{
try
{
//
TextMessage text = (TextMessage) message;
ObjectMessage
objectMessage = (ObjectMessage) message;
Queue
queue = (Queue) message.getJMSDestination ();
//
System.out.println ( queue.getQueueName () );
if
( queue.getQueueName ().equals ( ConfigManager.getPropertyValue (
"destination.mail.queueName" ) ) )
{
System.out.println
( queue.getQueueName () );
EmailBean
emailBean = (EmailBean) objectMessage.getObject ();
message.acknowledge
();
//
System.out.println ( new Date () + " : received the following message :
" + text.getText () );
EMail.getEmailInstance
().sendEmail ( emailBean.getTo (), emailBean.getCc (), emailBean.getBcc (),
emailBean.getSubject (), emailBean.getBodyContent () );
System.out.println
( new Date () + " : received the following message : " +
emailBean.getFrom () );
}
else
if ( queue.getQueueName ().equals ( ConfigManager.getPropertyValue (
"destination.sms.queueName" ) ) )
{
System.out.println
( queue.getQueueName () );
}
else
if ( queue.getQueueName ().equals ( ConfigManager.getPropertyValue (
"destination.fax.queueName" ) ) )
{
System.out.println
( queue.getQueueName () );
}
else
if ( queue.getQueueName ().equals ( ConfigManager.getPropertyValue (
"destination.auditTrail.queueName" ) ) )
{
System.out.println
( queue.getQueueName () );
}
else
if ( queue.getQueueName ().equals ( ConfigManager.getPropertyValue (
"destination.hlSeven.queueName" ) ) )
{
System.out.println
( queue.getQueueName () );
PatientInfoVO
patientInfoVO = (PatientInfoVO) objectMessage.getObject ();
message.acknowledge
();
new
JMSReceiverHelper ().addOrUpdatePatientDetails ( patientInfoVO );
}
}
catch
( JMSException e )
{
e.printStackTrace
();
}
catch
( Exception e )
{
e.printStackTrace
();
}
}
}
NOTE: QUEUE or TOPIC name should not be
contains numeric/special char.. [ like
hl7Queue ]