Send message to remote JMS queue - jms

I deployed an application on cluster1_machine1 and cluster2_machine2. The queue is in cluster1_machine1.
Using the application in cluster1_machine1 is fine with sending and receiving messages but it is fail in cluster2_machine2 to send a message to queue in cluster1_machine1.
I kept on get the following exception and I know the exception is thrown because of the following code.
WLSession s = (WLSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Exception:
java.lang.AbstractMethodError: retrieveThreadLocalContext
at weblogic.messaging.dispatcher.DispatcherProxy.unmarshalResponse(DispatcherProxy.java:243)
at weblogic.messaging.dispatcher.DispatcherProxy.dispatchSyncTranFuture(DispatcherProxy.java:134)
at weblogic.messaging.dispatcher.DispatcherWrapperState.dispatchSyncTran(DispatcherWrapperState.java:334)
at weblogic.messaging.dispatcher.DispatcherWrapperState.dispatchSyncNoTran(DispatcherWrapperState.java:381)
at weblogic.messaging.dispatcher.DispatcherWrapperState.dispatchSync(DispatcherWrapperState.java:249)
at weblogic.jms.dispatcher.DispatcherAdapter.dispatchSync(DispatcherAdapter.java:43)
at weblogic.jms.client.JMSConnection.setupJMSSession(JMSConnection.java:529)
at weblogic.jms.client.JMSConnection.createSessionInternal(JMSConnection.java:497)
at weblogic.jms.client.JMSConnection.createSession(JMSConnection.java:483)
at weblogic.jms.client.WLConnectionImpl.createSession(WLConnectionImpl.java:552)
at jsp_servlet.__enqueue._jspService(__enqueue.java:198)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:416)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:327)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3750)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3714)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2283)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2182)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1491)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Please kindly help. Thank you!
Code in producer:
try {
InitialContext ic = getInitialContext("t3://cluster2_machine2:<PORT>");
ConnectionFactory qconFactory = (ConnectionFactory) ic.lookup("jms/TestConnectionFactory");
Connection connection = qconFactory.createQueueConnection();
WLSession s = (WLSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination queue = (Destination) ic.lookup("jms/TestJMSQueue");
WLMessageProducer producer = (WLMessageProducer) s.createProducer(null);
TextMessage msg = s.createTextMessage();
connection.start();
msg.setText(strMsg);
producer.send(queue,msg);
producer.close();
s.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
private static InitialContext getInitialContext(String url)
throws NamingException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);
return new InitialContext(env);
}

Related

Websphere JMS queue connection issue - ConfigURL property file is not set

Facing the below exception when try to push msg into jms queue in Wrbsphere server.
Please let me know if any help can get on this.
Exception:
JSAS1480I: **Security is not enabled because the ConfigURL property file is not set.**
javax.naming.NamingException: Error getting WsnNameService properties [Root exception is org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: 0x4942f000 minor code: 3591 completed: No]
My code:
private void putmsg() throws NamingException, JMSException, IOException {
Context namingContext = null;
final Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
prop.put(Context.PROVIDER_URL, "iiop://localhost:2809");
prop.put(Context.SECURITY_PRINCIPAL, "admin");
prop.put(Context.SECURITY_CREDENTIALS, "admin");
prop.put("connection.factory", "jms/t24ConnectionFactory");
namingContext = new InitialContext(prop);
ConnectionFactory connectionFactory =
(ConnectionFactory) namingContext.lookup("jms/t24ConnectionFactory");
Destination queue = (Destination) namingContext.lookup("jms/t24OFSQueue");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession();
String input = FileUtils.readFileToString(new File("C:\\inflow\\ResponseOut1.xml"));
MessageProducer producer = session.createProducer(queue);
TextMessage txtMsg = session.createTextMessage(input);
((MessageProducer) producer).send(txtMsg);
connection.close();
}
I think i have missing some configuration related to websphere.

JMS Temporary Queue - Replies not returning back to client

I'm trying to move away from Weblogic to JBoss, and as such I'm trying to implement the things I was able to implement on Weblogic on JBoss.
One of those things is our notification system where the client sends a request to an MDB and the MDB sends a reply back to the client.
This was a breeze in Weblogic, but on Jboss, nothing seems to work. I keep getting this error:
javax.jms.InvalidDestinationException: Not an ActiveMQ Artemis Destination:ActiveMQTemporaryQueue[da00b1a2-114d-4be9-930d-926fc20c2fce]
Is there something I need to configure on my Jboss?
EDIT
I realise that I probably didn't phrase the question very well.
What happens is this: I have a client and a server MDB (message driven bean). The client sends a message to a queue and waits for a response from the server. The server picks the message from the queue and sends a response to the client, which the client picks up and displays.
On Jboss, messages from the client go smoothly, and the server picks it up, but as soon as the server MDB tries to send a response to the client, that error is thrown.
My client code (excerpt):
int TIME_OUT = 60000;
//prepare factory
Properties prop = new Properties();
prop.setProperty("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
prop.setProperty("java.naming.provider.url", "http-remoting://remotehost:8080");
prop.setProperty("java.naming.security.principal", "guest-user")
prop.setProperty("java.naming.security.credentials", "Password#1")
String queueConnectionFactory = "jms/RemoteConnectionFactory";
Context context = new InitialContext(prop);
QueueConnectionFactory qconFactory = (QueueConnectionFactory) context.lookup(queueConnectionFactory);
//prepare queue and sessions
QueueConnection qcon = qconFactory.createQueueConnection(prop.getProperty("java.naming.security.principal"), prop.getProperty("java.naming.security.credentials"));
QueueSession qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) context.lookup("jms/TestQueue2");
//create message
NotificationWrapper wrapper = //object initialised with something
ObjectMessage om = qsession.createObjectMessage(wrapper);//NotificationWrapper wrapper
//create producer
MessageProducer producer = qsession.createProducer(queue);
//create temporary queue
TemporaryQueue tempqueue = qsession.createTemporaryQueue();
om.setJMSReplyTo(tempqueue);
//start connection
qcon.start();
//send message and wait for response
producer.send(om);
MessageConsumer consumer = qsession.createConsumer(tempqueue);
Message callback = consumer.receive(TIME_OUT);
//print message from server
if (callback != null) {
System.out.println("Response received from server. Print here...");
//message from server
} else {
System.out.println("No Response received from server. Problems!!!");
}
//close all connections
if (consumer != null) {
consumer.close();
}
if (producer != null) {
producer.close();
}
if (qsession != null) {
qsession.close();
}
if (qcon != null) {
qcon.close();
}
My Server code (excerpt):
#MessageDriven(mappedName = "TestQueue2", activationConfig = {
#ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
#ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/TestQueue2"),
#ActivationConfigProperty(propertyName = "maxSession", propertyValue = "10")
})
public class ServerSide implements MessageListener {
private static final QueueConfigProperties queueConfigProp = QueueConfigProperties.getInstance();
private Context context;
private QueueConnectionFactory qconFactory;
private QueueConnection qcon;
private QueueSession qsession;
private MessageProducer producer;
public ServerSide() {
try {
initialiseQueueFactory("jms/RemoteConnectionFactory");
//initialiseQueueFactory("jms/GreenpoleConnectionFactory");
prepareResponseQueue();
Properties prop = new Properties();
prop.setProperty("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
prop.setProperty("java.naming.provider.url", "http-remoting://remotehost:8080");
prop.setProperty("java.naming.security.principal", "guest-user")
prop.setProperty("java.naming.security.credentials", "Password#1")
String queueConnectionFactory = "jms/RemoteConnectionFactory";
Context context = new InitialContext(prop);
QueueConnectionFactory qconFactory = (QueueConnectionFactory) context.lookup(queueConnectionFactory);
qcon = qconFactory.createQueueConnection(queueConfigProp.getProperty("java.naming.security.principal"), queueConfigProp.getProperty("java.naming.security.credentials"));
qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
} catch (NamingException | ConfigNotFoundException | IOException | JMSException ex) {
//error log
}
}
#Override
public void onMessage(Message message) {
try {
if (((ObjectMessage) message).getObject() instanceof NotificationWrapper) {
//send response
if (message.getJMSReplyTo() != null) {
logger.info("sending response");
respondToSenderPositive(message);
Response resp = new Response();
resp.setRetn(0);
resp.setDesc("Notification submitted to queue.");
producer = qsession.createProducer(message.getJMSReplyTo());
producer.send(qsession.createObjectMessage(resp));
producer.send(msg_to_send);
}
} else {
//some message printed here
}
} catch (JMSException ex) {
//error logs
} catch (Exception ex) {
//error logs
}
}
}
The issue was to do with the configuration of the destination queue which is a remote queue: the client and server are both running on different JVMs. Remote Queues on Jboss are named differently from those on Weblogic.
The name of a remote queue should be something like this: java:jboss/exported/jms/TestQueue2
Refer to the JBoss documentation for a more detailed explanation on queues: https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html-single/configuring_messaging/index

Ibm mq Connection through standalone server]

I am trying to connection to a ibm mq queue through standalone server.
(i am using 7.0.3 ibmmq jar)
cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, "dcc");
cf.setIntProperty(WMQConstants.WMQ_PORT, 14321);
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, "dfds");
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, "dw");
cf.setStringProperty(WMQConstants.USERID, "ww");
cf.setStringProperty(WMQConstants.PASSWORD, "vw");
i have set all these properties in connection Factory.
Conenction is made successfully but i am unable to open queue. getting the following error.
**MQJE001: Completion Code '2', Reason '6114'.**
FAILED: Queueconnection
com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ2008: Failed to open MQ queue 'US.0732931.NGEN.MANIFEST.LOADS'.
JMS attempted to perform an MQOPEN, but WebSphere MQ reported an error.
Use the linked exception to determine the cause of this error. Check that the specified queue and queue manager are defined correctly.
at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:585)
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:221)
You really don't provide enough information.
What connection factory are you using?
The error happens on the MQOPEN but you do NOT show the code for your createQueue method which is the important
Here's sample code:
private void putMessage()
{
JmsConnectionFactory cf = null;
Connection connection = null;
Session session = null;
Destination reqQ = null;
MessageProducer producer = null;
try
{
// Create a connection factory
JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
cf = ff.createConnectionFactory();
cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, "MY_QMGR_NAME");
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, "MY_TEST_CHL");
cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, "some_remote_server");
cf.setIntProperty(WMQConstants.WMQ_PORT, 1414);
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
cf.setStringProperty(WMQConstants.USERID, "my_uid");
cf.setStringProperty(WMQConstants.PASSWORD, "my_pwd");
// Create JMS objects
connection = cf.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
/**
* Create destination to send requests
* - MQA1 is the queue manager name
* - TEST.Q1 is the queue name
*/
reqQ = session.createQueue("queue://MQA1/TEST.Q1");
// Create producer
producer = session.createProducer(reqQ);
// Create a message
Message myMsg = session.createTextMessage("This is a test message.");
// Send it
producer.send(myMsg);
}
catch(Exception ex)
{
System.err.println(ex.getLocalizedMessage());
}
finally
{
try
{
session.close();
}
catch (Exception ex)
{
System.err.println("session.close() : " + ex.getLocalizedMessage());
}
try
{
connection.close();
}
catch (Exception ex)
{
System.err.println("connection.close() : " + ex.getLocalizedMessage());
}
}
}

Remove RFH2 header from incoming message in MQ

Currently i am using Websphere MQ V8.
public static void main(String[] args) throws JMSException {
// TODO Auto-generated method stub
try{
MQEnvironment.disableTracing();
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, "localhost");
cf.setStringProperty(WMQConstants.WMQ_PORT, "1414");
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, "TEST_SVR_CONN");
cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, "DEVTESTQUEUE");
//cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_DIRECT_HTTP);
//cf.setTransportType(WMQConstants.WMQ_CM_BINDINGS);
//set MQServer =
//HelloWorldConsumer.HelloWorldProducer();
MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
MQSession session = (MQSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueue queue = (MQQueue) session.createQueue("REQUEST");
//queue.setMessageBodyStyle(WMQConstants.WMQ_MESSAGE_BODY_MQ);
queue.setTargetClient(WMQConstants.WMQ_TARGET_DEST_MQ);
queue.setProperty("PROPCTL", "ALL");
((com.ibm.mq.jms.MQQueue)queue).setIntProperty(WMQConstants.WMQ_TARGET_CLIENT, WMQConstants.WMQ_TARGET_DEST_MQ);
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
consumer.setMessageListener(new HelloWorldConsumer());
session.close();
connection.close();
System.out.println("------END------");
}catch(JMSException je){
je.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}
i have tried by setting TARGCLIENT property to WMQ_TARGET_DEST_MQ and PROPCTL as "NONE/FORCE". Still iam getting the header in the message as
RFH ? ????MQSTR ? 25504.txt ?UPLOAD|1||

jms sending message on any server

I want to write generic code for sending message on any jms server. so for that i thought if i have jndi.properties file then we can place server configuration in this file and we can access this file through the code but i am able to do this only for 'ActiveMQ Server'. Now i am facing problems to send the message on any other server like glassfish server or jboss server. can somebody help me to do this task.
Here is my code :
public class Producer
{
public Producer() throws JMSException, NamingException,IOException
{
InputStream is = getClass().getResourceAsStream("my.jndi.properties");
Properties jndiParamaters = new Properties();
jndiParamaters.load(is);
Context jndi = new InitialContext(jndiParamaters);
ConnectionFactory conFactory = (ConnectionFactory) jndi.lookup("connectionFactory");
Connection connection;
connection = conFactory.createConnection();
try
{
connection.start();
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
Destination destination = (Destination) jndi.lookup("Myqueue");
MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage("Hello World!");
producer.send(message);
System.out.println("Sent message '" + message.getText() + "'");
}
finally
{
connection.close();
}
}
public static void main(String[] args) throws JMSException
{
try
{
BasicConfigurator.configure();
new Producer();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
thanks
Have you tried using the Spring JMS Template? http://static.springsource.org/spring/docs/2.0.x/reference/jms.html
It provides an abstraction layer to JMS and could probably help you when your implementation changes.

Resources