Commit 899d659c authored by afreyssin's avatar afreyssin
Browse files

Adds anothers producer and consumer.

parent 798a93b0
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2011 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package classic;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.objectweb.joram.client.jms.MessageConsumer;
import org.objectweb.joram.client.jms.Queue;
import org.objectweb.joram.client.jms.Session;
public class AConsumer {
public static void main(String[] args) throws Exception {
Context context = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) context.lookup("cf");
javax.jms.Queue queue =(Queue)context.lookup("queue");
context.close();
Connection cnx = cf.createConnection();
Session session = (Session) cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
// session.setImplicitAck(true);
session.setQueueMessageReadMax(100);
MessageConsumer consumer = (MessageConsumer) session.createConsumer(queue);
consumer.setMessageListener(new MyListener());
cnx.start();
System.in.read();
session.close();
cnx.close();
System.exit(0);
}
}
class MyListener implements MessageListener {
int nbMess=0;
public void onMessage(Message message) {
nbMess++;
if ( (nbMess % 1000) ==0 )
System.out.println(nbMess + " messages read");
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2011 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package classic;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.objectweb.joram.client.jms.Queue;
public class AProducer {
public static void main(String[] args) throws Exception {
Session session = null;
Connection cnx = null;
MessageProducer producer = null;
TextMessage message = null;
Queue queue = null;
ConnectionFactory cf = null;
Context initialContext = new InitialContext();
cf = (ConnectionFactory) initialContext.lookup("cf");
queue = (Queue) initialContext.lookup("queue");
initialContext.close();
cnx = cf.createConnection();
session = cnx.createSession(true, Session.AUTO_ACKNOWLEDGE);
cnx.start();
producer = session.createProducer(queue);
message = session.createTextMessage();
for (int i = 1; i <= 100000; i++) {
message.setText("Test number " + i);
producer.send(message);
if ((i % 100) == 0)session.commit();
if ((i % 1000) == 0) System.out.println(i + " messages sent");
}
session.commit();
producer.close();
session.close();
cnx.close();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment