I am doing a wildfy JMS program . After running this program it gives "null value".
Please give me a solution.
package com.itbuzzpress.jms;
import java.util.Properties;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSConsumer;
import javax.jms.JMSContext;
import javax.jms.Queue;
import javax.naming.Context;
import javax.naming.InitialContext;
public class JMSClient2 {
public static void main(String[] args) throws Exception {
Context namingContext = null;
JMSContext context = null;
try {
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
env.put(Context.PROVIDER_URL, "http-remoting://
127.0.0.1:8080");
env.put(Context.SECURITY_PRINCIPAL, "murad");
env.put(Context.SECURITY_CREDENTIALS, "Murad@1234");
namingContext = new InitialContext(env);
ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup("jms/RemoteConnectionFactory");
// Destination destination = (Destination) namingContext.lookup("jms/queue/exampleQueue");
Queue destination = (Queue) namingContext.lookup("jms/queue/exampleQueue");
context = connectionFactory.createContext("murad", "Murad@1234");
JMSConsumer consumer = context.createConsumer(destination);
String text = consumer.receiveBody(String.class, 9000);
if (text == null)
System.out.println("Received message with content " + text);
} catch (Exception e) {
System.out.println(e.getMessage());
throw e;
} finally {
if (namingContext != null) {
namingContext.close();
}
// closing the context takes care of consumer too
if (context != null) {
context.close();
}
}
}
}