public void start() throws JMSException { if (started.compareAndSet(false, true)) { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); queueConsumer = session.createConsumer(AdvisorySupport.QUEUE_ADVISORY_TOPIC); queueConsumer.setMessageListener(this); topicConsumer = session.createConsumer(AdvisorySupport.TOPIC_ADVISORY_TOPIC); topicConsumer.setMessageListener(this); tempQueueConsumer = session.createConsumer(AdvisorySupport.TEMP_QUEUE_ADVISORY_TOPIC); tempQueueConsumer.setMessageListener(this); tempTopicConsumer = session.createConsumer(AdvisorySupport.TEMP_TOPIC_ADVISORY_TOPIC); tempTopicConsumer.setMessageListener(this); } }
Destination dest = jmsProvider.destination(); this.connection = cf.createConnection(); this.session = connection.createSession(false, jmsAcknowledgeMode); MessageConsumer consumer = session.createConsumer(dest); consumer.setMessageListener(this); this.connection.start();
public void testNoIntercept() throws Exception { final CountDownLatch latch = new CountDownLatch(messageCount); consumer.setMessageListener(new MessageListener() { @Override public void onMessage(javax.jms.Message message) { latch.countDown(); } }); for (int i = 0; i < messageCount; i++){ javax.jms.Message message = producerSession.createTextMessage("test: " + i); producer.send(message); } latch.await(timeOutInSeconds, TimeUnit.SECONDS); assertEquals(0,latch.getCount()); }
try { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection conn = factory.createConnection(user, password); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer("test"); MessageConsumer consumer = session.createConsumer("test"); consumer.setMessageListener(this); // class that implements MessageListener conn.start(); TextMessage message = new ActiveMQTextMessage(); message.setText("TestMessage"); producer.send(message); } catch (JMSException e) { // somethings very wrong }
ServerListenerInfo(String id,Map holder,Destination replyTo,Session session) throws JMSException{ this.id=id; this.holder=holder; this.replyTo=replyTo; this.session=session; this.producer=session.createProducer(replyTo); Topic advisoryTopic=AdvisorySupport.getConsumerAdvisoryTopic((ActiveMQDestination) replyTo); advisoryConsumer=session.createConsumer(advisoryTopic); advisoryConsumer.setMessageListener(this); }
consumer.setMessageListener(new MessageListener() { @Override public void onMessage(javax.jms.Message message) { MessageConsumer consumer1 = consumerSession.createConsumer(testQueue); consumer1.setMessageListener(new MessageListener() { @Override public void onMessage(javax.jms.Message message) { for (int i = 0; i < messageCount; i++){ javax.jms.Message message = producerSession.createTextMessage("test: " + i); producer.send(message);
@Override @Before public void setUp() throws Exception { super.setUp(); sendConnection = createSendConnection(); sendConnection.start(); receiveConnection = createReceiveConnection(); receiveConnection.start(); session = createSendSession(sendConnection); receiveSession = createReceiveSession(receiveConnection); producer = session.createProducer(null); producer.setDeliveryMode(deliveryMode); if (topic) { consumerDestination = createDestination(session, ActiveMQDestination.TOPIC_TYPE); producerDestination = createDestination(session, ActiveMQDestination.TOPIC_TYPE); } else { consumerDestination = createDestination(session, ActiveMQDestination.QUEUE_TYPE); producerDestination = createDestination(session, ActiveMQDestination.QUEUE_TYPE); } consumer = createConsumer(receiveSession, consumerDestination); consumer.setMessageListener(this); }
@Override public void preStart() throws JMSException { final Destination destination = new JmsQueue(source); log.info("Creating AMQP Consumer for '{}'", source); if (session != null) { consumer = session.createConsumer(destination); consumer.setMessageListener((Message message) -> commandProcessor.forward(message, getContext())); } }
void receiveAndProcess(Queue queue, EntityManagerFactory entityManagerFactory, long waitTime, int countDown) throws Exception { Session qsession = qconnetion.createSession(true, QueueSession.AUTO_ACKNOWLEDGE); MessageConsumer consumer = qsession.createConsumer(queue); qconnetion.start(); consumer.setMessageListener(rec); Assertions.assertThat(latch.await(waitTime, TimeUnit.MILLISECONDS)).isTrue();
private void initializeJmsObjectsForQueue() throws JMSException { for (int i = 0; i < threads; i++) { Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE); if (destination == null) destination = session.createQueue(destinationName); MessageConsumer consumer = session.createConsumer(destination); IgniteJmsMessageListener messageListener = new IgniteJmsMessageListener(session, false); consumer.setMessageListener(messageListener); consumers.add(consumer); sessions.add(session); listeners.add(messageListener); } }
@Test public void testAckedMessageAreConsumed() throws Exception { connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(queueName); MessageProducer producer = session.createProducer(queue); producer.send(session.createTextMessage("Hello")); // Consume the message... MessageConsumer consumer = session.createConsumer(queue); consumer.setMessageListener(this); latch.await(10, TimeUnit.SECONDS); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Attempt to Consume the message...check if message was acknowledge consumer = session.createConsumer(queue); Message msg = consumer.receive(1000); assertNull(msg); session.close(); }
public StepManager(TimeoutWatch timeoutWatch, JmsConnection jmsConnection, String correlationId, long messageTimeToLive) throws JMSException { this.timeoutWatch = timeoutWatch; this.session = jmsConnection.getJmsSession(); this.correlationId = correlationId; if (getQueueInName() != null) { Queue queueIn = session.createQueue(getQueueInName()); consumer = session.createConsumer(queueIn, String.format(JMS_CORRELATION_ID_PATTERN, correlationId)); consumer.setMessageListener(this); } if (getQueueOutName() != null) { queueOut = session.createQueue(getQueueOutName()); sender = session.createProducer(queueOut); sender.setTimeToLive(messageTimeToLive); } else { queueOut = null; } this.messagesReceivedSuccess = new AtomicInteger(0); this.messagesReceivedFailed = new AtomicInteger(0); this.messagesToReceive = new AtomicInteger(0); }
public void testReRouteAll() throws Exception { final ActiveMQQueue queue = new ActiveMQQueue("Reroute.From."+topic.getTopicName()); final MessageInterceptorRegistry registry = MessageInterceptorRegistry.getInstance().get(BrokerRegistry.getInstance().findFirst()); registry.addMessageInterceptorForTopic(topic.getTopicName(), new MessageInterceptor() { @Override public void intercept(ProducerBrokerExchange producerExchange, Message message) { message.setDestination(queue); try { registry.injectMessage(producerExchange, message); } catch (Exception e) { e.printStackTrace(); } } }); final CountDownLatch latch = new CountDownLatch(messageCount); consumer = consumerSession.createConsumer(queue); consumer.setMessageListener(new MessageListener() { @Override public void onMessage(javax.jms.Message message) { latch.countDown(); } }); for (int i = 0; i < messageCount; i++){ javax.jms.Message message = producerSession.createTextMessage("test: " + i); producer.send(message); } latch.await(timeOutInSeconds, TimeUnit.SECONDS); assertEquals(0,latch.getCount()); }
public void testMessageListener() throws Exception { // send messages for (int i = 0; i < MESSAGE_COUNT; i++) { producer.send(session.createTextMessage(MESSAGE_TEXT + i)); } commitTx(); consumer.setMessageListener(this); // wait receive waitReceiveUnack(); assertEquals(unackMessages.size(), MESSAGE_COUNT); // resend phase waitReceiveAck(); assertEquals(ackMessages.size(), MESSAGE_COUNT); // should no longer re-receive consumer.setMessageListener(null); assertNull(consumer.receive(500)); reconnect(); }
protected synchronized void openAnswerQueue() throws JMSException { if (isClosed()) throw new JMSException("client closed: " + getName()); if (answerQueue == null || getSession() == null) { open(); answerQueue = dest.getConnection().getSession().createTemporaryQueue(); responseConsumer = dest.getConnection().getSession().createConsumer(answerQueue); responses = new HashMap<>(); responseConsumer.setMessageListener(this); } }
@Test public void testStartIdempotency() throws Exception { JmsBaseConnectionFactory connectionFactory = new JmsBaseConnectionFactory(new URI("rocketmq://xxx?consumerId=" + consumerId + "&nameServer=" + nameServer)); Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); checkConsumerState(consumerId, true, false); try { Destination destination = session.createTopic(topic + ":" + messageType); MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(listener); checkConsumerState(consumerId, false, false); ((JmsBaseMessageConsumer) consumer).startConsumer(); checkConsumerState(consumerId, false, true); Destination destination1 = session.createTopic(topic2 + ":" + messageType); MessageConsumer consumer1 = session.createConsumer(destination1); consumer1.setMessageListener(listener); ((JmsBaseMessageConsumer) consumer1).startConsumer(); checkConsumerState(consumerId, false, true); //the start is idempotent connection.start(); connection.start(); Thread.sleep(5000); } finally { connection.close(); } }
public void start() throws Exception { if (started.compareAndSet(false, true)) { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQTopic advisoryTopic = AdvisorySupport.getProducerAdvisoryTopic(destination); consumer = session.createConsumer(advisoryTopic); consumer.setMessageListener(this); } }
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); Destination dest = session.createQueue(queueName); final MessageConsumer consumer = session.createConsumer(dest); consumer.setMessageListener(new MessageListener() { MessageProducer producer = session.createProducer(dest); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); producer.send(session.createTextMessage("First")); producer.send(session.createTextMessage("Second"));
protected void doInit(InitialContext ctx) throws Exception { // channel = endpoint.getServiceUnit().getComponent().getComponentContext().getDeliveryChannel(); commonDoStartTasks(ctx); //Create temp destination of no reply destination found. if (endpoint.getJndiReplyToName() == null && endpoint.getJmsProviderReplyToName() == null) { if (destination instanceof Queue) { replyToDestination = session.createTemporaryQueue(); } else { replyToDestination = session.createTemporaryTopic(); } } producer = session.createProducer(destination); consumer = session.createConsumer(replyToDestination); consumer.setMessageListener(this); }
public void testReRouteAllWithNullProducerExchange() throws Exception { final ActiveMQQueue queue = new ActiveMQQueue("Reroute.From."+topic.getTopicName()); final MessageInterceptorRegistry registry = MessageInterceptorRegistry.getInstance().get(BrokerRegistry.getInstance().findFirst()); registry.addMessageInterceptorForTopic(topic.getTopicName(), new MessageInterceptor() { @Override public void intercept(ProducerBrokerExchange producerExchange, Message message) { message.setDestination(queue); try { registry.injectMessage(producerExchange, message); } catch (Exception e) { e.printStackTrace(); } } }); final CountDownLatch latch = new CountDownLatch(messageCount); consumer = consumerSession.createConsumer(queue); consumer.setMessageListener(new MessageListener() { @Override public void onMessage(javax.jms.Message message) { latch.countDown(); } }); for (int i = 0; i < messageCount; i++){ javax.jms.Message message = producerSession.createTextMessage("test: " + i); producer.send(message); } latch.await(timeOutInSeconds, TimeUnit.SECONDS); assertEquals(0,latch.getCount()); }