Hi.
I had a look in the JMX interface and there it says that 2 messages are pending in the
queue.
There is only one producer, consumer on each queue. So it should not happen that one
consumer buffers messages from another queue.
The producer should send 10.000 messages to one queue and the receivers expect to receive
10.000 messages. The receivers will prompt a message when all messages are received.
Producer:
initialization:
| public void init(String ip, int port, String qname) throws Exception {
| connection = createConnection(ip, port);
| connection.start();
| session = connection
| .createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
| try {
| q = (Queue) ctx.lookup(qname);
| } catch (Exception e) {
| q = session.createQueue(qname);
| ctx.bind(qname, q);
| }
| producer = session.createSender(q);
| }
|
| public QueueConnection createConnection(String ip, int port)
| throws NamingException, JMSException {
| try {
| ctx = (InitialContext) createContext(ip, 1099);
| } catch (Exception e) {
| e.printStackTrace();
| }
| QueueConnectionFactory qcf = (QueueConnectionFactory) ctx
| .lookup("ConnectionFactory");
| return qcf.createQueueConnection();
| }
|
| protected Context createContext(String ip, int port) throws Exception {
| String host = "jnp://" + ip + ":" + port;
| return createContext(host);
| }
|
| protected Context createContext(String host) throws Exception {
| Properties props = new Properties();
|
| props.put(Context.INITIAL_CONTEXT_FACTORY,
| "org.jnp.interfaces.NamingContextFactory");
| props.put(Context.PROVIDER_URL, host);
| props.put(Context.URL_PKG_PREFIXES,
| "org.jboss.naming:org.jnp.interfaces");
|
| return new InitialContext(props);
| }
|
sending messages:
| public void sendMsg(String msgtxt) throws Exception {
| TextMessage simpleMessage = session.createTextMessage();
| simpleMessage.setText(msgtxt);
| producer.send(simpleMessage);
| }
|
Consumer implements MessageListener:
inititalization:
| private void init(String ip, int port, String qname) throws JMSException,
| NamingException {
| connection = createConnection(ip, port);
| connection.start();
| session = connection.createQueueSession(false,
| QueueSession.AUTO_ACKNOWLEDGE);
| Queue q = session.createQueue(qname);
| msgConsumer = session.createReceiver(q);
| msgConsumer.setMessageListener(this);
| }
|
| public QueueConnection createConnection(String ip, int port)
| throws NamingException, JMSException {
| try {
| ctx = (InitialContext) createContext(ip, 1099);
| } catch (Exception e) {
| e.printStackTrace();
| }
| ConnectionFactory tmp = (ConnectionFactory) ctx
| .lookup("ConnectionFactory");
| QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
| return qcf.createQueueConnection();
| }
|
| // the default method
| protected Context createContext(String ip, int port) throws Exception {
| String host = "jnp://" + ip + ":" + port;
| return createContext(host);
| }
|
| protected Context createContext(String host) throws Exception {
| Properties props = new Properties();
|
| props.put(Context.INITIAL_CONTEXT_FACTORY,
| "org.jnp.interfaces.NamingContextFactory");
| props.put(Context.PROVIDER_URL, host);
| props.put(Context.URL_PKG_PREFIXES,
| "org.jboss.naming:org.jnp.interfaces");
|
| return new InitialContext(props);
| }
|
receiving messages:
| public void onMessage(Message msg) {
| cnt = cnt + 1;
| TextMessage txtMsg = (TextMessage) msg;
| if (cnt == msgToReceive) {
| running = !running;
| System.out.println(getClientId() + " Received all msg @ "
| + System.currentTimeMillis());
| cnt = 0;
| } else if (cnt > msgToReceive) {
| cnt = 0;
| }
| }
|
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4230396#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...