Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestQueue {
- Connection connection;
- Session session;
- Queue queueSend;
- private InitialContext ctxt = null;
- MessageProducer producer;
- public TestQueue() {
- }
- public static void main(String ar[]){
- TestQueue t;
- for (int i = 0; i < 500000; i++)
- try {
- t=new TestQueue();
- t.openJMSQueues();
- t.sendByJMS("msg"+i);
- t.closeJMSQueues();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void openJMSQueues()throws NamingException,JMSException
- {
- Properties props = new Properties();
- props.setProperty("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
- props.setProperty("java.naming.provider.url","t3://192.168.48.132:7001");
- props.setProperty(InitialContext.SECURITY_PRINCIPAL,"wapppush");
- props.setProperty(InitialContext.SECURITY_CREDENTIALS,"latinia");
- ctxt = new InitialContext(props);
- ConnectionFactory connectionFactory=null;
- connectionFactory = (ConnectionFactory) ctxt.lookup("latinia/limsp/jms/connectionFactory/XAConnectionFactory");
- queueSend = (Queue) ctxt.lookup("latinia/limsp/jms/queue/serviceToLimsp/normalAuth");
- connection = connectionFactory.createConnection();
- session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- producer=session.createProducer(queueSend);
- connection.start();
- }
- public void closeJMSQueues()
- {
- if (session != null) try {
- session.close();
- }
- catch(Exception ex) {
- System.out.println("error session.close()");
- }
- if (connection != null)
- try {
- connection.close();
- }
- catch(Exception ex) {
- System.out.println("error connection.close()");
- }
- }
- public void sendByJMS(String xml)throws JMSException{
- TextMessage txtMsg = session.createTextMessage(xml);
- txtMsg.setStringProperty("refProduct", "wapppush");
- producer.send(txtMsg);
- producer.send(session.createMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement