Channel End Notification exception is coming while using JMS with JBoss - java

I am using JMS with JBoss. But whenever i run the my consumer code i always get the below exception
[org.jboss.as.naming] (Remoting "sorabh216901" task-2) JBAS011806: Channel end notification received, closing channel Channel ID 091878ba (inbound) of Remoting connection 007ce8a6 to /192.168.2.47:53318
My Consumer class is as below:
public class TopicConsumer implements MessageListener{
public static void main(String[] args) throws NamingException, JMSException {
Context context = TopicConsumer.getInitialContext();
try{
System.out.println("Entering into the main method!!!");
TopicConnectionFactory connectionFactory = (TopicConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
Topic topic = (Topic) context.lookup("jms/topic/test");
TopicConnection connection = connectionFactory.createTopicConnection("testuser", "testpassword");
TopicSession session = connection.createTopicSession(true, TopicSession.AUTO_ACKNOWLEDGE);
session.createSubscriber(topic).setMessageListener(new TopicConsumer());
connection.start();
System.out.println("Exiting from the main method!!!");
}finally{
//context.close();
}
}
public void onMessage(Message arg0) {
System.out.println("Incoming Message : " + arg0);
}
public static Context getInitialContext() throws NamingException{
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
props.put(Context.PROVIDER_URL,"remote://192.168.2.47:4447");
props.put("jboss.naming.client.ejb.context", true);
// username
props.put(Context.SECURITY_PRINCIPAL, "testuser");
// password
props.put(Context.SECURITY_CREDENTIALS, "testpassword");
return new InitialContext(props);
}
}
When ever i ran the code i get the successful handshake in logs i.e.
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext#cd0d2e,
receiver=Remoting connection EJB receiver [connection=Remoting connection <1e03fce>,channel=jboss.ejb,nodename=sorabh216901]} on channel Channel ID 9823d1ac (outbound) of Remoting connection 004edf4a to /192.168.2.47:4447
But the program just closed and in server logs i get channel end notification.
Please suggest, what is wrong here.

Add the following line at the end of main method of TopConsumer
class:
try {
Thread.sleep(Integer.MAX_VALUE);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
This will not stop the JVM. And you won't get Channel End Notification exception

Related

Problem with initializing context with JMS [duplicate]

I'm trying to do a simple point-to-point chat, but after running the program I get an exception:
javax.naming.CommunicationException: Failed to get registry service for URL: tcp://localhost:8080/ [Root exception is java.rmi.ConnectIOException: Failed to create connection; nested exception is:
org.exolab.jms.net.connector.ConnectException: Failed to connect to localhost:8080]
at org.exolab.jms.jndi.InitialContextFactory.getInitialContext(InitialContextFactory.java:146)
at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:732)
at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
at java.naming/javax.naming.InitialContext.init(InitialContext.java:236)
at java.naming/javax.naming.InitialContext.<init>(InitialContext.java:208)
at zad1.Receiver.<init>(Receiver.java:24)
at zad1.Client.lambda$new$0(Client.java:61)
....
What could be the problem? I'm a complete beginner at this.
Here's my code:
private Context context;
private Connection connection = null;
private Session session;
private MessageProducer sender;
public Sender() {
try {
Hashtable<String, String> properties = new Hashtable<>();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.exolab.jms.jndi.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "tcp://localhost:8080/");
context = new InitialContext(properties);
ConnectionFactory factory = (ConnectionFactory) context.lookup("ConnectionFactory");
Topic topic = (Topic) context.lookup("topic1");
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
sender = session.createProducer(topic);
connection.start();
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
public void send(String message) {
try {
TextMessage textMessage = session.createTextMessage();
textMessage.setText(message);
sender.send(textMessage);
} catch (JMSException ex) {
ex.printStackTrace();
}
}
The message from the exception indicates what the problem is:
Failed to connect to localhost:8080
When you configure your JNDI lookup you specify:
properties.put(Context.PROVIDER_URL, "tcp://localhost:8080/");
However, the JNDI implementation can't establish a connection to localhost:8080. Please ensure that the URL is correct for your environment and/or that the JNDI server is actually running on port 8080 on localhost.
Lastly, it's worth noting that the stack-trace for the exception you shared does not match the source code you shared. The stack-trace came from the constructor of a class named Receiver, but the source code you shared is for a class named Sender.

JMS point-to-point chat

I'm trying to do a simple point-to-point chat, but after running the program I get an exception:
javax.naming.CommunicationException: Failed to get registry service for URL: tcp://localhost:8080/ [Root exception is java.rmi.ConnectIOException: Failed to create connection; nested exception is:
org.exolab.jms.net.connector.ConnectException: Failed to connect to localhost:8080]
at org.exolab.jms.jndi.InitialContextFactory.getInitialContext(InitialContextFactory.java:146)
at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:732)
at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
at java.naming/javax.naming.InitialContext.init(InitialContext.java:236)
at java.naming/javax.naming.InitialContext.<init>(InitialContext.java:208)
at zad1.Receiver.<init>(Receiver.java:24)
at zad1.Client.lambda$new$0(Client.java:61)
....
What could be the problem? I'm a complete beginner at this.
Here's my code:
private Context context;
private Connection connection = null;
private Session session;
private MessageProducer sender;
public Sender() {
try {
Hashtable<String, String> properties = new Hashtable<>();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.exolab.jms.jndi.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "tcp://localhost:8080/");
context = new InitialContext(properties);
ConnectionFactory factory = (ConnectionFactory) context.lookup("ConnectionFactory");
Topic topic = (Topic) context.lookup("topic1");
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
sender = session.createProducer(topic);
connection.start();
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
public void send(String message) {
try {
TextMessage textMessage = session.createTextMessage();
textMessage.setText(message);
sender.send(textMessage);
} catch (JMSException ex) {
ex.printStackTrace();
}
}
The message from the exception indicates what the problem is:
Failed to connect to localhost:8080
When you configure your JNDI lookup you specify:
properties.put(Context.PROVIDER_URL, "tcp://localhost:8080/");
However, the JNDI implementation can't establish a connection to localhost:8080. Please ensure that the URL is correct for your environment and/or that the JNDI server is actually running on port 8080 on localhost.
Lastly, it's worth noting that the stack-trace for the exception you shared does not match the source code you shared. The stack-trace came from the constructor of a class named Receiver, but the source code you shared is for a class named Sender.

Receive message from a topic subscription from azure servicebus via QPID JMS

I am following this tutorial to read messages from a given subscription. I have created a Receive class like this -
public class Receive implements MessageListener{
private static boolean runReceiver = true;
private Connection connection;
private Session sendSession;
private Session receiveSession;
private MessageProducer sender;
private MessageConsumer receiver;
private static Random randomGenerator = new Random();
public Receive() throws Exception {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("connectionfactory.SBCF", "amqps://All:[shared-access-key]#[namespace].servicebus.windows.net?amqp.idleTimeout=120000");
env.put("topic.TOPIC", "job/Subscriptions/job-test-subscription");
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
Context context = new InitialContext(env);
// Look up ConnectionFactory and Queue
ConnectionFactory cf = (ConnectionFactory) context.lookup("SBCF");
Destination queue = (Destination) context.lookup("TOPIC");
// Create Connection
connection = cf.createConnection();
// Create sender-side Session and MessageProducer
sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
sender = sendSession.createProducer(queue);
if (runReceiver) {
// Create receiver-side Session, MessageConsumer,and MessageListener
receiveSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
receiver = receiveSession.createConsumer(queue);
receiver.setMessageListener(this);
connection.start();
}
}
public void close() throws JMSException {
connection.close();
}
public void onMessage(Message message) {
try {
System.out.println("Received message with JMSMessageID = " + message.getJMSMessageID());
message.acknowledge();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
Receive simpleReceiver = new Receive();
} catch (Exception e) {
e.printStackTrace();
}
}
On executing this programI am getting this error -
log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
javax.jms.JMSException: hostname can't be null
at org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:86)
at org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:108)
at org.apache.qpid.jms.JmsConnection.connect(JmsConnection.java:172)
at org.apache.qpid.jms.JmsConnectionFactory.createConnection(JmsConnectionFactory.java:204)
at org.apache.qpid.jms.JmsConnectionFactory.createConnection(JmsConnectionFactory.java:191)
at Receive.<init>(Receive.java:41)
at Receive.main(Receive.java:63)
Caused by: java.io.IOException: hostname can't be null
at org.apache.qpid.jms.util.IOExceptionSupport.create(IOExceptionSupport.java:45)
at org.apache.qpid.jms.provider.amqp.AmqpProvider$2.run(AmqpProvider.java:217)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: hostname can't be null
at java.net.InetSocketAddress.checkHost(InetSocketAddress.java:149)
at java.net.InetSocketAddress.createUnresolved(InetSocketAddress.java:254)
at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:126)
at org.apache.qpid.jms.transports.netty.NettyTcpTransport.connect(NettyTcpTransport.java:167)
at org.apache.qpid.jms.provider.amqp.AmqpProvider$2.run(AmqpProvider.java:195)
... 7 more
Error is pointing towards this line - connection = cf.createConnection();
Also would like to know if providing my topic and subscription name like this -job/Subscriptions/job-test-subscription is fine or not.
Apologies for posting a long post.
According to the subsection Service Bus entity address from here, the job/Subscriptions/job-test-subscription value is your subscription address, not topic. Please change your url and topic property as below and try again.
connectionfactory.SBCF=amqps://All:[shared-access-key]#[namespace].servicebus.windows.net/job/Subscriptions/job-test-subscription?amqp.idleTimeout=120000
topic.TOPIC=job
Hope it helps.

jms queuebrowser # getEnumeration always obtained as empty

I'm using jbossall-client jar for JMS and I'm new to messaging. Whenever I try to browse the queue to which I send a message (its an object message), always I'm getting 'false' on my qBrowser.getEnumeration().hasMoreElements();
This is how I create the connection:
public void initialize() throws Exception {
try {
InitialContext initialContext = new InitialContext(contextProperties);
connectionFactory = (QueueConnectionFactory) initialContext.lookup(connectionFactoryName);
queue = (Queue) initialContext.lookup("queue/" + queueName);
initialContext.close();
} catch (NamingException e) {
throw new Exception("Error initializing enqueuer for " + queueName, e);
}
}
public MyQueueConnection openQueueConnection() throws JMSException {
QueueConnection connection = null;
try {
connection = connectionFactory.createQueueConnection();
connection.start();
QueueSession session = connection.createQueueSession(true, QueueSession.DUPS_OK_ACKNOWLEDGE);
QueueSender sender = session.createSender(queue);
sender.setDeliveryMode(DeliveryMode.PERSISTENT);
return new MyQueueConnection(connection, session, sender);
} catch (JMSException e) {
throw e;
}
}
Do I need to configure anything with QueueConnection/QueueSession/QueueSender or something else to browse the messages in a queue? Is it something I need to configure in jboss properties? (I do this in a singleton-MDB; this project is a spring framework project)
Please advise; thanks in advance.
Just a suggestion for another one.
I used hornetQ
Please check you created QueueReceiver createReceiver() after getEnumeration() is called.
Make sure you start connection connection.start()
Check the link for bug
Check the custom size

ActiveMQ connection times out even when wireFormat.maxInactivityDuration=0

I am listening to a queue of activemq.
My configuration is like below:
ACTIVEMQ_BROKER_URL =failover:(tcp://LON6QAEQTAPP01:61616?wireFormat.maxInactivityDuration=0)
From the console logs I can see that a reconnect attempt is made to connect to this server.
[2014-08-20 08:57:43,303] INFO 236[ActiveMQ Task-1] -
org.apache.activemq.transport.failover.FailoverTransport.doReconnect(FailoverTransport.java:1030)
- Successfully connected to tcp://LON6QAEQTAPP01:61616?wireFormat.maxInactivityDuration=0
[2014-08-20 08:57:43,355] INFO 288[ActiveMQ Task-1] -
org.apache.activemq.transport.failover.FailoverTransport.doReconnect(FailoverTransport.java:1030)
- Successfully connected to tcp://LON6QAEQTAPP01:61616?wireFormat.maxInactivityDuration=0
[2014-08-20 08:57:43,374] INFO 307[ActiveMQ Task-1] -
org.apache.activemq.transport.failover.FailoverTransport.doReconnect(FailoverTransport.java:1030)
- Successfully connected to tcp://LON6QAEQTAPP01:61616?wireFormat.maxInactivityDuration=0
Still I am not able to consume the message. I am using the following code to try and handle it from code side but still not able to get the connection persistent.
try
{
connection.start();
while (true)
{
try
{
if (connection.isClosed() || connection.isTransportFailed() || session.isClosed() || !connection.getTransport().isConnected())
{
log.info("Connection was reset, re-connecting..");
connection.cleanup();
init();
connection.start();
}
}
catch (Throwable t)
{
init();
log.error("Connection was reset, re-connecting in exception block", t);
}
Thread.sleep(30000L);
}
private void init() throws Exception
{
init(brokerURL, queueName, userName, password, manual);
}
public void init(String brokerURL, String queueName, String userName, String password, boolean manual) throws Exception
{
this.manual = manual;
this.brokerURL = brokerURL;
this.queueName = queueName;
this.userName = userName;
this.password = password;
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(userName, password, brokerURL);
connection = (ActiveMQConnection) connectionFactory.createConnection();
connection.addTransportListener(new TransportListener()
{
#Override
public void transportResumed()
{
log.info("Transport Resumed ");
}
#Override
public void transportInterupted()
{
log.info("Transport Interupted ");
}
#Override
public void onException(IOException arg0)
{
arg0.printStackTrace();
log.error("Transport Exception: " + arg0.getMessage());
}
#Override
public void onCommand(Object arg0)
{
// TODO Auto-generated method stub
}
});
connection.setExceptionListener(this);
connection.setCloseTimeout(10);
session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);// CLIENT_ACKNOWLEDGE
Destination destination = session.createQueue(queueName);
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(this);
}
Can someone help me as to how can I get this connection to be active alive all the time. It generally times out after inactivity of 40 mins or so.
Trying to force reconnect an open connection the way you are is definitely not going to do you and good. You need to tear down the connection and create a new one if you want to handle connection interruption yourself. What you really should do is figure out what is closing your connection on you, probably a firewall closing down the inactive connection or a load balancer. Look at your environment and see what else is in the mix that could be closing the connection on you.
The broker can, if configured to do so, rebalance clients in a cluster. Are you using multiple clients in a clustered environment etc?

Categories

Resources