org.apache.activemq.ActiveMQConnection Java Examples
The following examples show how to use
org.apache.activemq.ActiveMQConnection.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AcknowledgementExample.java From scava with Eclipse Public License 2.0 | 7 votes |
public void run() throws Exception { BrokerService broker = new BrokerService(); broker.setUseJmx(true); broker.setPersistent(false); broker.addConnector("tcp://localhost:61616"); broker.start(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL); ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection(); connection.start(); ActiveMQSession session = (ActiveMQSession) connection. createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE); Queue queue = session.createQueue("queue"); createConsumer(session, queue, "Consumer 1", false); createConsumer(session, queue, "Consumer 2", true); MessageProducer producer = session.createProducer(queue); for (int i=0;i<10;i++) { producer.send(session.createTextMessage("Message " + i)); Thread.sleep(100); } }
Example #2
Source File: FTPBlobUploadStrategyTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void testFileUpload() throws Exception { setConnection(); File file = File.createTempFile("amq-data-file-", ".dat"); // lets write some data BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.append("hello world"); writer.close(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ((ActiveMQConnection) connection).setCopyMessageOnSend(false); ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession) session).createBlobMessage(file); message.setJMSMessageID("testmessage"); message.onSend(); assertEquals(ftpUrl + "ID_testmessage", message.getURL().toString()); File uploaded = new File(ftpHomeDirFile, "ID_testmessage"); assertTrue("File doesn't exists", uploaded.exists()); }
Example #3
Source File: JmsProxyImpl.java From c2mon with GNU Lesser General Public License v3.0 | 6 votes |
/** * Runs until (re)connected. Should only be called by one thread. Use * startReconnectThread to run in another thread (only one thread will be * started however many calls are made). * <p> * Listeners are notified of connection once the connection is reestablished * and all topic subscriptions are back. */ private synchronized void connect() { while (!connected && !shutdownRequested) { try { connection = (ActiveMQConnection) jmsConnectionFactory.createConnection(); connection.start(); connection.addTransportListener((ActiveMQTransportListener) this::startReconnectThread); refreshSubscriptions(); connected = true; } catch (Exception e) { log.error("Exception caught while trying to refresh the JMS connection; sleeping 5s before retrying.", e); try { wait(SLEEP_BETWEEN_CONNECTION_ATTEMPTS); } catch (InterruptedException interEx) { log.error("InterruptedException caught while waiting to reconnect.", interEx); } } } if (connected) { notifyConnectionListenerOnConnection(); } }
Example #4
Source File: JMSConnectionFactoryTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Test create topic connection * * @throws Exception */ @Test public void testCreateTopicConnections() throws Exception { String topicName = "testCreateConT"; Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(topicName, PROVIDER_URL, true); JMSConnectionFactory connectionFactory = new JMSConnectionFactory(jmsProperties); JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties); try { brokerController.startProcess(); TopicConnection topicConnection = connectionFactory.createTopicConnection(); Assert.assertTrue("The queue connection is created", ((ActiveMQConnection) topicConnection). getTransport().getRemoteAddress().contains("61616")); TopicConnection topicConnectionWithCred = connectionFactory.createTopicConnection("admin", "admin"); Assert.assertTrue("The queue connection is created", ((ActiveMQConnection) topicConnectionWithCred). getTransport().getRemoteAddress().contains("61616")); } finally { brokerController.disconnect(); brokerController.stopProcess(); } }
Example #5
Source File: ProductConsumerA.java From jim-framework with Apache License 2.0 | 6 votes |
@Override public void onMessage(Message message) { String transport= ((ActiveMQConnection)((ActiveMQObjectMessage)message).getConnection()).getTransport().toString(); String text= ""; try { text = ((ActiveMQObjectMessage)message).getObject().toString(); } catch (JMSException e) { e.printStackTrace(); } if(Product.transportResult.containsKey(transport)){ Product.transportResult.get(transport).add(text); } else { List<String> productList=new ArrayList<>(); productList.add(text); Product.transportResult.put(transport,productList); } System.out.println("Consumer,productId:"+text+"transport:"+transport); }
Example #6
Source File: ProductConsumerB.java From jim-framework with Apache License 2.0 | 6 votes |
@Override public void onMessage(Message message) { String transport= ((ActiveMQConnection)((ActiveMQObjectMessage)message).getConnection()).getTransport().toString(); String text= ""; try { text = ((ActiveMQObjectMessage)message).getObject().toString(); } catch (JMSException e) { e.printStackTrace(); } if(Product.transportResult.containsKey(transport)){ Product.transportResult.get(transport).add(text); } else { List<String> productList=new ArrayList<>(); productList.add(text); Product.transportResult.put(transport,productList); } System.out.println("Consumer,productId:"+text+"transport:"+transport); }
Example #7
Source File: Producer.java From jms with MIT License | 6 votes |
public void create(String clientId, String queueName) throws JMSException { this.clientId = clientId; // create a Connection Factory ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( ActiveMQConnection.DEFAULT_BROKER_URL); // create a Connection connection = connectionFactory.createConnection(); connection.setClientID(clientId); // create a Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // create the Queue to which messages will be sent Queue queue = session.createQueue(queueName); // create a MessageProducer for sending messages messageProducer = session.createProducer(queue); }
Example #8
Source File: JMSConnectionFactoryTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Test stop/Close connection * * @throws Exception */ @Test public void testStopConnection() throws Exception { String queueName = "testStopCon"; Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(queueName, PROVIDER_URL, true); JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties); try { brokerController.startProcess(); JMSConnectionFactory connectionFactory = new JMSConnectionFactory(jmsProperties); Connection connection = connectionFactory.getConnection(); connectionFactory.start(connection); Assert.assertTrue("The connection should be started", ((ActiveMQConnection) connection).isStarted()); connectionFactory.stop(connection); Assert.assertFalse("The connection should be stopped", ((ActiveMQConnection) connection).isStarted()); boolean isClosed = connectionFactory.closeConnection(connection); Assert.assertTrue("The connection should be closed", isClosed); //Exception should be thrown and caught thrown when trying to start/stop/close closed connection connectionFactory.start(connection); connectionFactory.stop(connection); ; } finally { brokerController.disconnect(); brokerController.stopProcess(); } }
Example #9
Source File: Subscriber.java From jms with MIT License | 6 votes |
public void create(String clientId, String topicName) throws JMSException { this.clientId = clientId; // create a Connection Factory ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( ActiveMQConnection.DEFAULT_BROKER_URL); // create a Connection connection = connectionFactory.createConnection(); connection.setClientID(clientId); // create a Session Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // create the Topic from which messages will be received Topic topic = session.createTopic(topicName); // create a MessageConsumer for receiving messages messageConsumer = session.createConsumer(topic); // start the connection in order to receive messages connection.start(); }
Example #10
Source File: UnidentifiedProducer.java From jms with MIT License | 6 votes |
public void create() throws JMSException { // create a Connection Factory ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( ActiveMQConnection.DEFAULT_BROKER_URL); // create a Connection connection = connectionFactory.createConnection(); // create a Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // create a Message Producer for sending messages messageProducer = session.createProducer(null); }
Example #11
Source File: ActiveMQMessageProducerSendInterceptor.java From pinpoint with Apache License 2.0 | 6 votes |
private boolean validateTransport(ActiveMQSession session) { if (session == null) { return false; } ActiveMQConnection connection = session.getConnection(); if (!(connection instanceof TransportGetter)) { if (isDebug) { logger.debug("Invalid connection object. Need field accessor({}).", TransportGetter.class.getName()); } return false; } Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport()); if (!(transport instanceof SocketGetter)) { if (isDebug) { logger.debug("Transport not traceable({}).", transport.getClass().getName()); } return false; } return true; }
Example #12
Source File: Producer.java From jms with MIT License | 6 votes |
public void create(String destinationName) throws JMSException { // create a Connection Factory ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( ActiveMQConnection.DEFAULT_BROKER_URL); // create a Connection connection = connectionFactory.createConnection(); // create a Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // create the Destination to which messages will be sent Destination destination = session.createQueue(destinationName); // create a Message Producer for sending messages messageProducer = session.createProducer(destination); }
Example #13
Source File: DeadLetterTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override protected void doTest() throws Exception { connection.start(); ActiveMQConnection amqConnection = (ActiveMQConnection) connection; rollbackCount = amqConnection.getRedeliveryPolicy().getMaximumRedeliveries() + 1; LOG.info("Will redeliver messages: " + rollbackCount + " times"); makeConsumer(); makeDlqConsumer(); sendMessages(); // now lets receive and rollback N times for (int i = 0; i < messageCount; i++) { consumeAndRollback(i); } for (int i = 0; i < messageCount; i++) { Message msg = dlqConsumer.receive(1000); assertMessage(msg, i); assertNotNull("Should be a DLQ message for loop: " + i, msg); } session.commit(); }
Example #14
Source File: JMSConnectionFactoryTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Test create queue connection * * @throws Exception */ @Test public void testCreateQueueConnections() throws Exception { String queueName = "testCreateConQ"; Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(queueName, PROVIDER_URL, true); JMSConnectionFactory connectionFactory = new JMSConnectionFactory(jmsProperties); JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties); try { brokerController.startProcess(); QueueConnection queueConnection = connectionFactory.createQueueConnection(); Assert.assertTrue("The queue connection is created", ((ActiveMQConnection) queueConnection). getTransport().getRemoteAddress().contains("61616")); QueueConnection queueConnectionWithCred = connectionFactory.createQueueConnection("admin", "admin"); Assert.assertTrue("The queue connection is created", ((ActiveMQConnection) queueConnectionWithCred). getTransport().getRemoteAddress().contains("61616")); } finally { brokerController.disconnect(); brokerController.stopProcess(); } }
Example #15
Source File: FTPBlobUploadStrategyTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void testWriteDenied() throws Exception { userNamePass = "guest"; setConnection(); File file = File.createTempFile("amq-data-file-", ".dat"); // lets write some data BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.append("hello world"); writer.close(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ((ActiveMQConnection) connection).setCopyMessageOnSend(false); ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession) session).createBlobMessage(file); message.setJMSMessageID("testmessage"); try { message.onSend(); } catch (JMSException e) { e.printStackTrace(); return; } fail("Should have failed with permission denied exception!"); }
Example #16
Source File: FailoverClusterTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testClusterConnectedBeforeClients() throws Exception { server1.start(); server2.start(); Assert.assertTrue(server1.waitClusterForming(100, TimeUnit.MILLISECONDS, 20, 2)); Assert.assertTrue(server2.waitClusterForming(100, TimeUnit.MILLISECONDS, 20, 2)); createClients(); server1.stop(); Thread.sleep(1000); URI brokerBURI = new URI(newURI(2)); for (ActiveMQConnection c : connections) { String addr = c.getTransportChannel().getRemoteAddress(); Assert.assertTrue(addr.indexOf("" + brokerBURI.getPort()) > 0); } }
Example #17
Source File: FailoverClusterTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testClusterConnectedAfterClients() throws Exception { server1.start(); createClients(); Set<String> set = new HashSet<>(); server2.start(); Assert.assertTrue(server1.waitClusterForming(100, TimeUnit.MILLISECONDS, 20, 2)); Assert.assertTrue(server2.waitClusterForming(100, TimeUnit.MILLISECONDS, 20, 2)); Thread.sleep(3000); for (ActiveMQConnection c : connections) { System.out.println("======> adding address: " + c.getTransportChannel().getRemoteAddress()); set.add(c.getTransportChannel().getRemoteAddress()); } System.out.println("============final size: " + set.size()); Assert.assertTrue(set.size() > 1); }
Example #18
Source File: FailoverTimeoutTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testUpdateUris() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + tcpUri + ")?useExponentialBackOff=false"); ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection(); try { connection.start(); FailoverTransport failoverTransport = connection.getTransport().narrow(FailoverTransport.class); URI[] bunchOfUnknownAndOneKnown = new URI[]{new URI("tcp://unknownHost:" + tcpUri.getPort()), new URI("tcp://unknownHost2:" + tcpUri.getPort()), new URI("tcp://localhost:2222")}; failoverTransport.add(false, bunchOfUnknownAndOneKnown); } finally { if (connection != null) { connection.close(); } } }
Example #19
Source File: ActiveMQMessageConsumerDispatchInterceptor.java From pinpoint with Apache License 2.0 | 6 votes |
private boolean validateTransport(ActiveMQSession session) { if (session == null) { return false; } ActiveMQConnection connection = session.getConnection(); if (!(connection instanceof TransportGetter)) { if (isDebug) { logger.debug("Invalid connection object. Need field accessor({}).", TransportGetter.class.getName()); } return false; } Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport()); if (!(transport instanceof SocketGetter)) { if (isDebug) { logger.debug("Transport not traceable({}).", transport.getClass().getName()); } return false; } return true; }
Example #20
Source File: DiscardingDeadLetterPolicyTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override protected void doTest() throws Exception { connection.start(); ActiveMQConnection amqConnection = (ActiveMQConnection) connection; rollbackCount = amqConnection.getRedeliveryPolicy().getMaximumRedeliveries() + 1; LOG.info("Will redeliver messages: " + rollbackCount + " times"); makeConsumer(); makeDlqConsumer(); sendMessages(); // now lets receive and rollback N times for (int i = 0; i < messageCount; i++) { consumeAndRollback(i); } for (int i = 0; i < messageCount; i++) { Message msg = dlqConsumer.receive(1000); assertNull("Should not be a DLQ message for loop: " + i, msg); } session.commit(); }
Example #21
Source File: AbortSlowAckConsumer0Test.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testZeroPrefetchConsumerIsAborted() throws Exception { strategy.setMaxTimeSinceLastAck(2000); // Make it shorter ActiveMQConnection conn = (ActiveMQConnection) createConnectionFactory().createConnection(); conn.setExceptionListener(this); connections.add(conn); Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); final MessageConsumer consumer = sess.createConsumer(destination); assertNotNull(consumer); conn.start(); startProducers(destination, 20); Message message = consumer.receive(5000); assertNotNull(message); TimeUnit.SECONDS.sleep(15); try { consumer.receive(5000); fail("Slow consumer not aborted."); } catch (Exception ex) { } }
Example #22
Source File: SimpleNetworkTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 60 * 1000) public void testMessageCompression() throws Exception { ActiveMQConnection localAmqConnection = (ActiveMQConnection) localConnection; localAmqConnection.setUseCompression(true); MessageConsumer consumer1 = remoteSession.createConsumer(included); MessageProducer producer = localSession.createProducer(included); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); waitForConsumerRegistration(localBroker, 1, included); for (int i = 0; i < MESSAGE_COUNT; i++) { Message test = localSession.createTextMessage("test-" + i); producer.send(test); Message msg = consumer1.receive(3000); assertNotNull(msg); ActiveMQMessage amqMessage = (ActiveMQMessage) msg; assertTrue(amqMessage.isCompressed()); } // ensure no more messages received assertNull(consumer1.receive(1000)); }
Example #23
Source File: AbortSlowAckConsumer0Test.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testIdleConsumerCanBeAborted() throws Exception { strategy.setIgnoreIdleConsumers(false); strategy.setMaxTimeSinceLastAck(2000); // Make it shorter ActiveMQConnection conn = (ActiveMQConnection) createConnectionFactory().createConnection(); conn.setExceptionListener(this); connections.add(conn); Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); final MessageConsumer consumer = sess.createConsumer(destination); assertNotNull(consumer); conn.start(); startProducers(destination, 1); Message message = consumer.receive(5000); assertNotNull(message); message.acknowledge(); // Consumer needs to be closed before the receive call. TimeUnit.SECONDS.sleep(15); try { consumer.receive(5000); fail("Idle consumer not aborted."); } catch (Exception ex) { } }
Example #24
Source File: MessageCompressionTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void sendTestMessage(ActiveMQConnectionFactory factory, String message) throws JMSException { ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(queue); producer.send(session.createTextMessage(message)); connection.close(); }
Example #25
Source File: ActiveMQMessageConsumerDispatchInterceptor.java From pinpoint with Apache License 2.0 | 5 votes |
private void recordRootSpan(SpanRecorder recorder, Object target, Object[] args) { recorder.recordServiceType(ActiveMQClientConstants.ACTIVEMQ_CLIENT); recorder.recordApi(CONSUMER_ENTRY_METHOD_DESCRIPTOR); ActiveMQSession session = ((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession(); ActiveMQConnection connection = session.getConnection(); Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport()); final String endPoint = getEndPoint(transport); // Endpoint should be the local socket address of the consumer. recorder.recordEndPoint(endPoint); final String remoteAddress = transport.getRemoteAddress(); // Remote address is the socket address of where the consumer is connected to. recorder.recordRemoteAddress(remoteAddress); MessageDispatch md = (MessageDispatch) args[0]; ActiveMQMessage message = (ActiveMQMessage) md.getMessage(); ActiveMQDestination destination = message.getDestination(); // Rpc name is the URI of the queue/topic we're consuming from. recorder.recordRpcName(destination.getQualifiedName()); // Record acceptor host as the queue/topic name in order to generate virtual queue node. recorder.recordAcceptorHost(destination.getPhysicalName()); String parentApplicationName = ActiveMQClientHeader.getParentApplicationName(message, null); if (!recorder.isRoot() && parentApplicationName != null) { short parentApplicationType = ActiveMQClientHeader.getParentApplicationType(message, ServiceType.UNDEFINED.getCode()); recorder.recordParentApplication(parentApplicationName, parentApplicationType); } }
Example #26
Source File: MessageCompressionTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private ActiveMQBytesMessage receiveTestBytesMessage(ActiveMQConnectionFactory factory) throws JMSException, UnsupportedEncodingException { ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(queue); ActiveMQBytesMessage rc = (ActiveMQBytesMessage) consumer.receive(); connection.close(); return rc; }
Example #27
Source File: DbRestartJDBCQueueMasterSlaveLeaseQuiesceTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override protected void verifyExpectedBroker(int inflightMessageCount) { if (inflightMessageCount == 0 || (inflightMessageCount == failureCount + 10 && restartDelay <= 500)) { assertEquals("connected to master", master.getBrokerName(), ((ActiveMQConnection) sendConnection).getBrokerName()); } else { // lease expired while DB was offline, either or master/slave can grab it so assert is not deterministic // but we still need to validate sent == received } }
Example #28
Source File: IndividualDeadLetterTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void testDLQBrowsing() throws Exception { super.topic = false; deliveryMode = DeliveryMode.PERSISTENT; durableSubscriber = false; messageCount = 1; connection.start(); ActiveMQConnection amqConnection = (ActiveMQConnection) connection; rollbackCount = amqConnection.getRedeliveryPolicy().getMaximumRedeliveries() + 1; LOG.info("Will redeliver messages: " + rollbackCount + " times"); sendMessages(); // now lets receive and rollback N times for (int i = 0; i < rollbackCount; i++) { makeConsumer(); Message message = consumer.receive(5000); assertNotNull("No message received: ", message); session.rollback(); LOG.info("Rolled back: " + rollbackCount + " times"); consumer.close(); } makeDlqBrowser(); browseDlq(); dlqBrowser.close(); session.close(); Thread.sleep(1000); session = connection.createSession(transactedMode, acknowledgeMode); Queue testQueue = new ActiveMQQueue("ActiveMQ.DLQ.Queue.ActiveMQ.DLQ.Queue." + getClass().getName() + "." + getName()); MessageConsumer testConsumer = session.createConsumer(testQueue); assertNull("The message shouldn't be sent to another DLQ", testConsumer.receive(1000)); }
Example #29
Source File: NioQueueSubscriptionTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Ignore("See AMQ-4286") @Test(timeout = 60 * 1000) public void testLotsOfConcurrentConnections() throws Exception { ExecutorService executor = Executors.newCachedThreadPool(); final ConnectionFactory factory = createConnectionFactory(); int connectionCount = 400; final AtomicInteger threadId = new AtomicInteger(0); for (int i = 0; i < connectionCount; i++) { executor.execute(new Runnable() { @Override public void run() { final int innerId = threadId.incrementAndGet(); try { ExceptionListener listener = new NioQueueSubscriptionTestListener(innerId, exceptions, LOG); ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection(); connection.setExceptionListener(listener); connection.start(); assertNotNull(connection.getBrokerName()); connections.add(connection); } catch (Exception e) { LOG.error(">>>> Exception in run() on thread " + innerId, e); exceptions.put(Thread.currentThread(), e); } } }); } executor.shutdown(); executor.awaitTermination(30, TimeUnit.SECONDS); if (!exceptions.isEmpty()) { LOG.error(">>>> " + exceptions.size() + " exceptions like", exceptions.values().iterator().next()); fail("unexpected exceptions in worker threads: " + exceptions.values().iterator().next()); } LOG.info("created " + connectionCount + " connections"); }
Example #30
Source File: MessageListenerDeadLetterTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override protected void doTest() throws Exception { messageCount = 200; connection.start(); ActiveMQConnection amqConnection = (ActiveMQConnection) connection; rollbackCount = amqConnection.getRedeliveryPolicy().getMaximumRedeliveries() + 1; LOG.info("Will redeliver messages: " + rollbackCount + " times"); makeConsumer(); makeDlqConsumer(); sendMessages(); // now lets receive and rollback N times int maxRollbacks = messageCount * rollbackCount; consumer.setMessageListener(new RollbackMessageListener(maxRollbacks, rollbackCount)); for (int i = 0; i < messageCount; i++) { Message msg = dlqConsumer.receive(4000); if (error[0] != null) { // error from message listener throw error[0]; } assertMessage(msg, i); assertNotNull("Should be a DLQ message for loop: " + i, msg); } if (error[0] != null) { throw error[0]; } }