Why does my routing params in JMS turn out to be null?
Hello!I try to set a param with the method setStringProperty("x", "y").
But when I try to read it, during consuming, with getStringProperty("x), I just get "null".
I really hope that some one can help me out with this problem.
I send a JMS message to a local queue at my MQ with the following code:
public static void send() throws Exception
{
System.out.println("Start");
Properties properties = new Properties();
properties.setProperty("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
properties.setProperty("java.naming.provider.url", "file:C://Fredrik//Eclipse_workspace//distribution//resources");
Context ctxNaming = new InitialContext(properties);
QueueConnectionFactory factory = (QueueConnectionFactory) ctxNaming.lookup("queue.connection.factory");
QueueConnection connection = factory.createQueueConnection();
connection.start();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctxNaming.lookup("MYQUEUE");
QueueSender sender = session.createSender(queue);
BytesMessage responseMessage = session.createBytesMessage();
responseMessage.writeBytes("hubba".getBytes());
responseMessage.setStringProperty("testkey", "testvalue");
System.out.println("\n test: " + responseMessage.getStringProperty("testkey") );
sender.send(responseMessage);
session.close();
connection.close();
System.out.println("Stop");
}
It looks like the param get set since:
System.out.println("\n test: " + responseMessage.getStringProperty("testkey") );
...prints out:
test: testvalue
But when I read and consume the message with the following code:
public static void read() throws Exception
{
System.out.println("Start");
Properties properties = new Properties();
properties.setProperty("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
properties.setProperty("java.naming.provider.url", "file:C://Fredrik//Eclipse_workspace//distribution//resources");
Context ctxNaming = new InitialContext(properties);
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) ctxNaming.lookup("queue.connection.factory");
QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
queueConnection.start();
QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (javax.jms.Queue) ctxNaming.lookup("MYQUEUE");
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
Message message = queueReceiver.receiveNoWait();
if(message instanceof TextMessage)
{
logger.debug("\n"+((TextMessage)message).getText() );
}
if(message instanceof BytesMessage)
{
System.out.println("\n test: " + message.getStringProperty("testkey") );
System.out.println("\n test: " + ((BytesMessage)message).getStringProperty("testkey") );
}
else
{
logger.debug("\n"+message.toString());
}
queueSession.close();
queueConnection.close();
System.out.println("Stop");
}
I just get:
test: null.
I really can not figure out why?
So if any one got an idea or clue, please let me know.
Best regards
Fredrik
