[JBoss Messaging] - Re: All messages are not persisted in Database.
by sajankn
I tried to merge both subscriber and publisher code into a single file, but I'm not able to reproduce the same situation for this single file. It can be reproduced only if both run in separate jvm and in a clustered mode.
| import javax.jms.JMSException;
| import javax.jms.TextMessage;
| import javax.jms.Topic;
| import javax.jms.TopicConnection;
| import javax.jms.TopicConnectionFactory;
| import javax.jms.TopicPublisher;
| import javax.jms.TopicSession;
| import javax.jms.TopicSubscriber;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
|
| public class MyTest
| {
| private String destinationName;
| private TopicConnectionFactory cf;
| private Topic topic;
| private Topic [] topicArr;
| private TopicConnection connection;
| private TopicSession session;
| private TopicSession sessionPub;
| private TopicSubscriber subscriber;
| private TopicPublisher [] publisher;
| private int publisherCount = 5;
|
| public static void main(String[] args)
| {
| MyTest obj = new MyTest();
| obj.init();
| obj.subscribe();
| obj.publish();
| //obj.cleanup();
| }
|
| public void init()
| {
| try
| {
| destinationName = "/topic/testTopic";
| InitialContext ic = new InitialContext();
| cf = (TopicConnectionFactory)ic.lookup("/ClusteredConnectionFactory");
| topic = (Topic)ic.lookup(destinationName);
| connection = cf.createTopicConnection("admin", "admin");
| connection.setClientID("MyClientID");
| session = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
| sessionPub = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
| subscriber = session.createDurableSubscriber(topic, "MyName");
| publisher = new TopicPublisher[publisherCount];
| topicArr = new Topic[publisherCount];
| for (int j=0; j<publisherCount; j++)
| {
| topicArr[j] = (Topic)ic.lookup(destinationName);
| publisher[j] = sessionPub.createPublisher(topicArr[j]);
| }
| ic = null;
| connection.start();
| }
| catch(JMSException jmse)
| {
| jmse.printStackTrace();
| }
| catch(NamingException ne)
| {
| ne.printStackTrace();
| }
| catch(Exception e)
| {
| e.printStackTrace();
| }
| }
|
| private class SubscriberMessages extends Thread
| {
| public void run()
| {
| try
| {
| while (true)
| {
| TextMessage message = (TextMessage)subscriber.receive(5000);
| if (message != null)
| {
| String msgStr = message.getText();
| System.out.println(msgStr);
| }
| message = null;
| }
| }
| catch(JMSException jmse)
| {
| jmse.printStackTrace();
| }
| catch(Exception e)
| {
| e.printStackTrace();
| }
| }
| }
|
| public void subscribe()
| {
| SubscriberMessages sObj = new SubscriberMessages();
| sObj.start();
| }
|
| private class PublishMessages extends Thread
| {
| private int pubID = 0;
| public PublishMessages(int id)
| {
| pubID = id;
| }
| public void run()
| {
| try
| {
| String msgStr = "Hello World";
| for (int i = 0; i< 1000; i++)
| {
| TextMessage tm = session.createTextMessage(msgStr + i);
| publisher[pubID].publish(tm);
| }
| }
| catch(JMSException jmse)
| {
| jmse.printStackTrace();
| }
| catch(Exception e)
| {
| e.printStackTrace();
| }
| }
| }
|
| public void publish()
| {
| for (int i=0; i<publisherCount; i++)
| {
| PublishMessages pObj = new PublishMessages(i);
| pObj.start();
| }
|
| }
|
| public void cleanup()
| {
| try
| {
| try
| {
| if (subscriber != null)
| subscriber.close();
| }
| catch(Exception e)
| {
| }
| try
| {
| for (int j=0; j<publisherCount; j++)
| {
| if (publisher[j] != null)
| publisher[j].close();
| }
| }
| catch(Exception e)
| {
| }
| try
| {
| if (connection != null)
| connection.stop();
| }
| catch(Exception e)
| {
| }
| try
| {
| if (session != null)
| session.close();
| }
| catch(Exception e)
| {
| }
| try
| {
| if (connection != null)
| connection.close();
| }
| catch(Exception e)
| {
| }
| }
|
| catch(Exception e)
| {
| e.printStackTrace();
| }
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4168598#4168598
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4168598
17 years, 8 months
[JBoss Messaging] - Messaging DLQ not clustering correctly
by tnine
Hi All,
I have an old EJB 2 MDB that listens from a queue and processes messages. When a message fails, it goes to the default DLQ. I have 2 nodes in my cluster, prodjboss1, and prodjboss2. We have a process that runs on a timer and wakes up every 30 seconds to check the DLQ for failed messages. Those messages are then read from the queue, and written to a file on disk for manual inspection. We ran into an issue today, where the DLQ on prodjboss1 was empty but the DLQ on prodjboss2 had a message in it. I've configured the DLQ to be clustered, but it doesn't appear that the nodes are clustering. Whenever the client wakes up and inspects the DLQ, it never receives any messages if they're not on prodjboss1. Here is my DLQ config from both nodes as well as my client's JNDI properties. Is something configured incorrectly for clustering of the DLQ? All my other queues that are clustered work as intended, messages are shared across nodes and clients.
Thanks,
Todd
DLQ config
| <mbean code="org.jboss.jms.server.destination.QueueService"
| name="jboss.messaging.destination:service=Queue,name=DLQ"
| xmbean-dd="xmdesc/Queue-xmbean.xml">
| <depends optional-attribute-name="ServerPeer">
| jboss.messaging:service=ServerPeer
| </depends>
| <depends>jboss.messaging:service=PostOffice</depends>
| <attribute name="Clustered">true</attribute>
| </mbean>
|
|
Client config
| java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
| java.naming.factory.url.pkgs= org.jboss.naming:org.jnp.interfaces
| #Development host
| #java.naming.provider.url=jnp://localhost:1100
| #Production host
| java.naming.provider.url=jnp://prodjboss1:1100,jnp://prodjboss2:1100
|
Versions:
JBoss 4.2.2 GA custom config. All configuration with web serivces removed
JBoss Messaging 1.4
Java 1.5
Redhat 5
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4168591#4168591
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4168591
17 years, 8 months