List of usage examples for javax.jms Session AUTO_ACKNOWLEDGE
int AUTO_ACKNOWLEDGE
To view the source code for javax.jms Session AUTO_ACKNOWLEDGE.
Click Source Link
From source file:sk.seges.test.jms.multiple.QueueSendReceiveTest.java
@Test public void testReceive() throws Exception { Connection connection = testConnectionFactory.createConnection(); connection.start();/*w w w. j a va 2 s. c o m*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(testQueueA); Message rawMessage = consumer.receive(); assertTrue(rawMessage instanceof TextMessage); TextMessage message = (TextMessage) rawMessage; assertEquals("test text", message.getText()); connection.close(); }
From source file:com.navercorp.pinpoint.demo.gateway.configuration.GatewayConfiguration.java
@Bean Session session(Connection amqConnection) throws JMSException { return amqConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); }
From source file:org.wso2.andes.systest.MergeConfigurationTest.java
/** * Test that setting messageCount takes affect on topics * * We send 10 messages and disconnect at 9 * * @throws Exception//from www. j av a2 s .c o m */ public void testTopicConsumerMessageCount() throws Exception { MAX_QUEUE_MESSAGE_COUNT = 10; configureTopic(getName(), (MAX_QUEUE_MESSAGE_COUNT * 4) - 1); //Configure topic as a subscription setProperty(".topics.topic(" + topicCount + ").subscriptionName", "clientid:" + getTestQueueName()); configureTopic(getName(), (MAX_QUEUE_MESSAGE_COUNT - 1)); //Start the broker startBroker(); topicConsumer(Session.AUTO_ACKNOWLEDGE, true); }
From source file:org.wso2.carbon.sample.consumer.JMSQueueMessageConsumer.java
public void run() { // create queue connection QueueConnection queueConnection = null; try {//from ww w. j a va 2s . c o m queueConnection = queueConnectionFactory.createQueueConnection(); queueConnection.start(); } catch (JMSException e) { log.info("Can not create queue connection." + e); return; } Session session = null; try { session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(queueName); MessageConsumer consumer = session.createConsumer(destination); int count = 0; long totalLatency = 0; long lastTimestamp = System.currentTimeMillis(); while (active) { Message message = consumer.receive(1000); if (message != null) { // if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; long currentTime = System.currentTimeMillis(); long sentTimestamp = (Long) mapMessage.getObject("time"); totalLatency = totalLatency + (currentTime - sentTimestamp); int logCount = 1000; if ((count % logCount == 0) && (count > warmUpCount)) { double rate = (logCount * 1000.0d / (System.currentTimeMillis() - lastTimestamp)); log.info("Consumer: " + consumerId + " (" + logCount + " received) rate: " + rate + " Latency:" + (totalLatency / (logCount * 1.0d))); // log.info("total latency:" + totalLatency); log.info("Total rate: " + (int) (consumers * rate)); totalLatency = 0; lastTimestamp = System.currentTimeMillis(); } count++; } } log.info("Finished listening for messages."); } catch (JMSException e) { log.info("Can not subscribe." + e); } finally { if (session != null) { try { session.close(); } catch (JMSException e) { log.error(e); } } try { queueConnection.stop(); queueConnection.close(); } catch (JMSException e) { e.printStackTrace(); } } }
From source file:de.adorsys.jmspojo.JMSJavaFutureAdapterTest.java
@Before public void setup() throws Exception { broker = new BrokerService(); broker.setPersistent(false);/*www .j a v a2 s.c o m*/ // configure the broker broker.addConnector("vm://test"); broker.setBrokerName("test"); broker.setUseShutdownHook(false); broker.start(); cf = new ActiveMQConnectionFactory("vm://localhost?create=false"); qc = cf.createQueueConnection(); QueueSession createQueueSession = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); testQueue = createQueueSession.createQueue("TestQueue"); createQueueSession.createReceiver(testQueue).setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { boolean sendTimeout = message.getBooleanProperty("timeout"); boolean sendError = message.getBooleanProperty("error"); if (sendError) { JMSJavaFutureAdapter<PingMessage> jmsSender = new JMSJavaFutureAdapter<PingMessage>( objectMapper, cf, null, TIMEOUT); HashMap<String, Object> messageProperties = new HashMap<String, Object>(); messageProperties.put("ERROR", "test error"); jmsSender.send(message.getJMSReplyTo(), messageProperties, null); } else if (!sendTimeout) { JMSJavaFutureAdapter<PingMessage> jmsSender = new JMSJavaFutureAdapter<PingMessage>( objectMapper, cf, null, TIMEOUT); jmsSender.send(message.getJMSReplyTo(), null, ((TextMessage) message).getText()); } } catch (JMSException e) { e.printStackTrace(); } } }); qc.start(); }
From source file:biz.fstechnology.micro.server.jms.AbstractJmsService.java
/** * @see biz.fstechnology.micro.server.Service#init() */// ww w . j a va 2s. co m @Override public void init() throws Exception { Connection connection = createJmsTemplate().getConnectionFactory().createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(session.createTopic(getListenTopic())); consumer.setMessageListener(this); replyProducer = session.createProducer(null); replyProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); connection.start(); }
From source file:org.logicblaze.lingo.jmx.remote.jms.MBeanJmsServerConnectionClient.java
/** * Construct this thing/*from www. j av a2 s. c o m*/ * * @param connection * @throws JMSException */ public MBeanJmsServerConnectionClient(MBeanJmsServerConnection connection, Connection jmsConnection) throws JMSException { super(connection); this.serverConnection = connection; Session jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); replyToDestination = jmsSession.createTemporaryTopic(); MessageConsumer consumer = jmsSession.createConsumer(replyToDestination); consumer.setMessageListener(this); }
From source file:org.apache.servicemix.wsn.jms.JmsPullPoint.java
protected void initSession() throws JMSException { if (session == null) { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); queue = session.createQueue(getName()); producer = session.createProducer(queue); consumer = session.createConsumer(queue); }/*w w w . j av a2 s . c o m*/ }
From source file:nl.han.dare2date.jms.JMSPublisher.java
public boolean connect(String topicName) { try {/*from w ww . j a va2 s. c om*/ context = JMSUtil.getContext(); } catch (NamingException e) { logger.error("Can't create context", e); return false; } catch (IOException e) { logger.error("Can't create context", e); return false; } connection = JMSUtil.getConnection(); try { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } catch (JMSException e) { logger.error("Can't create session", e); return false; } Destination topic = null; try { topic = (Topic) context.lookup(topicName); } catch (NamingException e) { logger.error("Can't load topic by name", e); return false; } try { topicPublisher = session.createProducer(topic); } catch (JMSException e) { logger.error("Can't create producer", e); return false; } return true; }
From source file:de.adorsys.jmspojo.JMSServiceAdapterFactoryTest.java
@Before public void setup() throws Exception { broker = new BrokerService(); broker.setPersistent(false);//from ww w . j av a 2 s . c o m // configure the broker broker.addConnector("vm://test"); broker.setBrokerName("test"); broker.setUseShutdownHook(false); broker.start(); cf = new ActiveMQConnectionFactory("vm://localhost?create=false"); qc = cf.createQueueConnection(); QueueSession createQueueSession = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); defaultQueue = createQueueSession.createQueue("TestQueue"); createQueueSession.createReceiver(defaultQueue).setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { boolean sendTimeout = message.getBooleanProperty("timeout"); if (!sendTimeout) { JMSJavaFutureAdapter<PingMessage> jmsSender = new JMSJavaFutureAdapter<PingMessage>( OBJECT_MAPPER, cf, null, JMS_TIMEOUT); jmsSender.send(message.getJMSReplyTo(), null, ((TextMessage) message).getText()); } } catch (JMSException e) { e.printStackTrace(); } } }); dedicatedQueue = createQueueSession.createQueue("DedicatedQueue"); createQueueSession.createReceiver(dedicatedQueue).setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { JMSJavaFutureAdapter<PingMessage> jmsSender = new JMSJavaFutureAdapter<PingMessage>( OBJECT_MAPPER, cf, null, JMS_TIMEOUT); PingMessage data = new PingMessage(); data.setPing("dedicted response"); jmsSender.send(message.getJMSReplyTo(), null, data); } catch (JMSException e) { e.printStackTrace(); } } }); qc.start(); JMSServiceAdapterFactory jmsServiceStubFactory = new JMSServiceAdapterFactory(OBJECT_MAPPER, cf, defaultQueue, JMS_TIMEOUT); service = jmsServiceStubFactory.generateJMSServiceProxy(JMSSampleService.class); }