protected void initMQ() throws Exception { long start = System.currentTimeMillis(); while (true) { try { mqCon = connectionFactory.createConnection(); break; } catch (Exception e) { if (System.currentTimeMillis() - start < 5 * 60000)// try for 5 // mins { Thread.sleep(5000); } else throw e; } } mqCon.start(); // Create the session session = mqCon.createSession(false, Session.AUTO_ACKNOWLEDGE); queue = session.createQueue(queueName); producer = session.createProducer(queue); mqCon.setExceptionListener(this); }
有些资源打开一次就好了。‘重复打开会很浪费时间。
producer = session.createProducer(queue);
异步消息:
tcp://192.168.1.1:61616?jms.useAsyncSend=true&jms.producerWindowSize=1024000