|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Can a JMS Listener consume non-JMS (straight mq) messages? |
« View previous topic :: View next topic » |
Author |
Message
|
smalltalk2k |
Posted: Tue May 03, 2005 4:34 am Post subject: Can a JMS Listener consume non-JMS (straight mq) messages? |
|
|
Novice
Joined: 03 May 2005 Posts: 10
|
Is if possible to have a JMS Listener consume non-JMS straight text messages that were written to the queue using regular MQ java api.
I've tried multiple ways but I can't seem to do it. I just want to make sure I haven't missed something.
an example message would be pure text, written using java MQ api.
"123,test,130581,textPart 2, blah, blah"
Can you read this text message that was written to a queue using the MQ Api with the JMS api and process it? If so how can I access the 'text' of the message? The Jms text message class doesn't seem to be doing the trick.
thanks |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue May 03, 2005 4:40 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
How do you know it's not working? What error is it throwing? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
smalltalk2k |
Posted: Tue May 03, 2005 5:43 am Post subject: |
|
|
Novice
Joined: 03 May 2005 Posts: 10
|
ahh, you just have to love programming. My program was throwing class cast exceptions when i tried to access the text message last night. Today it is working fine. I didn't make any programming changes, I just closed WSAD and restarted my computer for the new day. |
|
Back to top |
|
 |
bower5932 |
Posted: Tue May 03, 2005 7:41 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
If you restarted your computer, then your qmgr got shutdown and restarted. I'd guess that you had some 'bad' messages in your queue that got thrown away with the qmgr shutdown. The next time you see the error, you can try running the amqsbcg program against the queue to see what the messages look like. |
|
Back to top |
|
 |
smalltalk2k |
Posted: Wed Jun 01, 2005 5:13 am Post subject: |
|
|
Novice
Joined: 03 May 2005 Posts: 10
|
just as an FYI. here is the code that I'm using to read the pure mq messages with jms. It was made to run as a thread. It has transactions for commit and rollback.
Code: |
package gov.usda.fsa.mq;
import gov.usda.fsa.db.CTCSResultSet;
import gov.usda.fsa.db.CTCSResultSetException;
import gov.usda.fsa.tools.CTCSActivityMessageHandler;
import gov.usda.fsa.tools.CTCSQuery;
import gov.usda.fsa.tools.CTCSWebLog;
import java.util.Hashtable;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.log4j.Logger;
/*
* Created on Jul 30, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author jason.richardson
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class FieldServer7Reciever extends Thread {
static Logger log = Logger.getLogger(CTCSWebLog.class.getName());
private boolean running = false;
private static final class SingletonHolder {
static final FieldServer7Reciever _singleton =
new FieldServer7Reciever();
}
private FieldServer7Reciever() {
}
public static FieldServer7Reciever getInstance() {
return SingletonHolder._singleton;
}
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
//public static void main(String[] args) {}
public void run() {
markRunning();
String queueName = null;
InitialContext context = null;
QueueConnectionFactory qcf = null;
QueueConnection conn = null;
QueueSession session = null;
Queue q = null;
QueueReceiver receiver = null;
TextMessage message = null;
try {
//com.ibm.mq.jms.context.WMQInitialContextFactory
String icf = Messages.getString("JMS_TEST7.CONTEXT_FACTORY"); //$NON-NLS-1$
//String icf = "com.ibm.websphere.naming.WsnInitialContextFactory";
String url = Messages.getString("JMS_TEST7.URL"); //$NON-NLS-1$
// Initialise JNDI properties
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, icf);
env.put(Context.PROVIDER_URL, url);
context = new InitialContext(env);
//final InitialContext context = new InitialContext();
// Lookup the queue connection factory from the
// initial context.
//QueueConnectionFactory fact = (QueueConnectionFactory)new MQQueueConnectionFactory();
//fact.
qcf = (QueueConnectionFactory) context.lookup(Messages.getString("JMS_TEST7.SERVER_NAME")); //$NON-NLS-1$
// Create a new queue connection from the queue
// connection factory.
conn = qcf.createQueueConnection();
// Create a new queue session from the queue
// connection. The session should not be transacted
// and should use automatic message acknowledgement.
session = conn.createQueueSession(true, -1);
// Lookup the queue to be used to send and receive
// messages from the initial context.
q = (Queue) context.lookup(Messages.getString("JMS_TEST7.QUEUE_NAME")); //$NON-NLS-1$
// Create a new queue receiver using the queue session.
// The queue receiver should be created to receive
// messages from the queue q.
receiver = session.createReceiver(q);
// Start the connection
conn.start();
log.debug(Messages.getString("JMS_TEST7.MESSAGE_CONNECTED")); //$NON-NLS-1$
// Use the queue receiver to receive the message that
// was sent previously.
log.debug(Messages.getString("JMS_TEST7.MESSAGE_LISTENER_STARTED")); //$NON-NLS-1$
boolean dbSuccess = true;
while (isRunning() ) {
//dbtest();
log.debug("FieldServer 7 checking for messages...");
dbSuccess = true;
Message m = receiver.receive(5000);
if (m != null) {
if (m instanceof TextMessage) {
message = (TextMessage) m;
log.debug(
"FieldServer 7 Message: " + message.getText());
dbSuccess =
CTCSActivityMessageHandler.handleMessage(message);
if (dbSuccess) {
log.debug("FieldServer 7 COMMITING JMS");
session.commit();
} else {
log.debug("FieldServer 7 ROLLING BACK JMS");
session.rollback();
}
} else {
log.debug(Messages.getString("JMS_TEST7.MESSAGE_NON_TEXT_RECIEVED")); //$NON-NLS-1$
stopLoop();
log.debug("FieldServer 7 COMMITING JMS");
session.commit();
}
} else {
// commit the null message
log.debug("FieldServer 7 COMMITING JMS");
session.commit();
}
//yield();
}
} catch (NamingException ne) {
try {
log.debug("FieldServer 7 ROLLING BACK JMS");
session.rollback();
} catch (Exception ex1) {
log.warn(this, ex1);
}
log.warn(this, ne);
} catch (JMSException jmse) {
try {
log.debug("FieldServer 7 ROLLING BACK JMS");
session.rollback();
} catch (Exception ex1) {
log.warn(this, ex1);
}
Exception linkedException = jmse.getLinkedException();
if (linkedException != null) {
log.warn(this, linkedException);
}
log.warn(this, jmse);
} catch (Exception exc) {
try {
log.debug("FieldServer 7 ROLLING BACK JMS");
session.rollback();
} catch (Exception ex1) {
log.warn(this, ex1);
}
log.warn(this, exc);
} finally {
stopLoop();
if (conn != null) {
try {
log.debug(Messages.getString("JMS_TEST7.MESSAGE_CLOSING_CONNECTION")); //$NON-NLS-1$
conn.stop();
conn.close();
log.debug(Messages.getString("JMS_TEST7.MESSAGE_CLOSED_CONNECTION")); //$NON-NLS-1$
} catch (JMSException e) {
log.warn(this, e);
}
}
}
}
public void stopLoop() {
log.debug("Field Server 7 Activity Tracking Listener marked for STOP");
running = false;
}
private void stopLoop(boolean flag) {
running = flag;
}
public boolean isStopped() {
return !running;
}
public boolean isRunning() {
return running;
}
private void markRunning() {
running = true;
}
private void dbtest(){
CTCSResultSet rs = CTCSQuery.executeQuery("select * from message_queue");
if (rs.hasRows()) {
log.debug("-Rows found-");
rs.beforeFirst();
while (rs.next()) {
try {
log.debug(rs.getString("message_queue_name") + " "+ rs.getString("message_queue_identifier"));
} catch (CTCSResultSetException e) {
e.printStackTrace();
}
}
} else {
}
}
}
|
|
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|