Java Code Examples for org.apache.activemq.command.ActiveMQDestination#isTopic()
The following examples show how to use
org.apache.activemq.command.ActiveMQDestination#isTopic() .
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: JMSPollingConsumerTopicTest.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Test polling on topic using JMS inbound endpoint task * * @throws Exception */ @Test public void testPollingOnTopic() throws Exception { String topicName = "testTopic1"; boolean isTopicExist = false; Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(topicName, PROVIDER_URL, false); JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties); JMSPollingConsumer jmsPollingConsumer = new JMSPollingConsumer(jmsProperties, INTERVAL, INBOUND_EP_NAME); InboundTask task = new JMSTask(jmsPollingConsumer, INTERVAL); try { brokerController.startProcess(); task.execute(); ActiveMQDestination[] activeMQDestination = brokerController.getBrokerService().getRegionBroker(). getDestinations(); for (ActiveMQDestination destination : activeMQDestination) { if (destination.isTopic() && topicName.equals(destination.getPhysicalName())) { isTopicExist = true; } } Assert.assertTrue("Topic is not added as a subscription", isTopicExist); } finally { task.destroy(); brokerController.stopProcess(); } }
Example 2
Source File: JMSPollingConsumerTopicTest.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Test polling on durable topic using JMS inbound endpoint task * * @throws Exception */ @Test public void testPollingOnDurableTopic() throws Exception { String topicName = "testTopic2"; boolean isTopicExist = false; Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(topicName, PROVIDER_URL, false); jmsProperties.put(JMSConstants.PARAM_SUB_DURABLE, "true"); JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties); JMSPollingConsumer jmsPollingConsumer = new JMSPollingConsumer(jmsProperties, INTERVAL, INBOUND_EP_NAME); InboundTask task = new JMSTask(jmsPollingConsumer, INTERVAL); try { brokerController.startProcess(); task.execute(); Set<ActiveMQDestination> activeMQDestination = brokerController.getBrokerService().getRegionBroker(). getDurableDestinations(); for (ActiveMQDestination destination : activeMQDestination) { if (destination.isTopic() && topicName.equals(destination.getPhysicalName())) { isTopicExist = true; } } Assert.assertTrue("Topic is not added as a subscription", isTopicExist); } finally { task.destroy(); brokerController.stopProcess(); } }
Example 3
Source File: ArtemisBrokerWrapper.java From activemq-artemis with Apache License 2.0 | 6 votes |
public long getAMQueueMessageCount(ActiveMQDestination amq5Dest) { if (amq5Dest.isTopic()) { throw new IllegalArgumentException("Method only accept queue type parameter."); } long count = 0; String qname = null; if (amq5Dest.isTemporary()) { qname = amq5Dest.getPhysicalName(); } else { qname = amq5Dest.getPhysicalName(); } Binding binding = server.getPostOffice().getBinding(new SimpleString(qname)); if (binding != null) { QueueImpl q = (QueueImpl) binding.getBindable(); count = q.getMessageCount(); } return count; }
Example 4
Source File: QueueSubscriptionTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void doMultipleClientsTest() throws Exception { // Create destination final ActiveMQDestination dest = createDestination(); // Create consumers ActiveMQConnectionFactory consumerFactory = (ActiveMQConnectionFactory) createConnectionFactory(); consumerFactory.getPrefetchPolicy().setAll(prefetchCount); startConsumers(consumerFactory, dest); startProducers(dest, messageCount); // Wait for messages to be received. Make it proportional to the // messages delivered. int totalMessageCount = messageCount * producerCount; if (dest.isTopic()) { totalMessageCount *= consumerCount; } waitForAllMessagesToBeReceived(totalMessageCount); }
Example 5
Source File: JMSPollingConsumerTopicTest.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Test polling on durable topic using JMS inbound endpoint task when the JMS Spec Version is 2.0 * * @throws Exception */ @Test public void testPollingOnDurableTopicV2() throws Exception { String topicName = "testTopic3"; boolean isTopicExist = false; Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(topicName, PROVIDER_URL, false); jmsProperties.put(JMSConstants.PARAM_SUB_DURABLE, "true"); jmsProperties.put(JMSConstants.PARAM_JMS_SPEC_VER, JMSConstants.JMS_SPEC_VERSION_2_0); JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties); JMSPollingConsumer jmsPollingConsumer = new JMSPollingConsumer(jmsProperties, INTERVAL, INBOUND_EP_NAME); InboundTask task = new JMSTask(jmsPollingConsumer, INTERVAL); try { brokerController.startProcess(); task.execute(); Set<ActiveMQDestination> activeMQDestination = brokerController.getBrokerService().getRegionBroker(). getDurableDestinations(); for (ActiveMQDestination destination : activeMQDestination) { if (destination.isTopic() && topicName.equals(destination.getPhysicalName())) { isTopicExist = true; } } Assert.assertTrue("Topic is not added as a subscription", isTopicExist); } finally { task.destroy(); brokerController.stopProcess(); } }
Example 6
Source File: JMSPollingConsumerTopicTest.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Test polling on durable topic using JMS inbound endpoint task when the JMS Spec Version is 1.0 * * @throws Exception */ @Test public void testPollingOnDurableTopicV1() throws Exception { String topicName = "testTopic4"; boolean isTopicExist = false; Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(topicName, PROVIDER_URL, false); jmsProperties.put(JMSConstants.PARAM_SUB_DURABLE, "true"); jmsProperties.put(JMSConstants.PARAM_JMS_SPEC_VER, JMSConstants.JMS_SPEC_VERSION_1_0); JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties); JMSPollingConsumer jmsPollingConsumer = new JMSPollingConsumer(jmsProperties, INTERVAL, INBOUND_EP_NAME); InboundTask task = new JMSTask(jmsPollingConsumer, INTERVAL); try { brokerController.startProcess(); task.execute(); Set<ActiveMQDestination> activeMQDestination = brokerController.getBrokerService().getRegionBroker(). getDurableDestinations(); for (ActiveMQDestination destination : activeMQDestination) { if (destination.isTopic() && topicName.equals(destination.getPhysicalName())) { isTopicExist = true; } } Assert.assertTrue("Topic is not added as a subscription", isTopicExist); } finally { task.destroy(); brokerController.stopProcess(); } }
Example 7
Source File: AbortSlowConsumer0Test.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testSlowConsumerIsAbortedViaJmx() throws Exception { underTest.setMaxSlowDuration(60 * 1000); // so jmx does the abort startConsumers(withPrefetch(2, destination)); Entry<MessageConsumer, MessageIdList> consumertoAbort = consumers.entrySet().iterator().next(); consumertoAbort.getValue().setProcessingDelay(8 * 1000); for (Connection c : connections) { c.setExceptionListener(this); } startProducers(destination, 100); consumertoAbort.getValue().assertMessagesReceived(1); ActiveMQDestination amqDest = (ActiveMQDestination) destination; ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost"); DestinationViewMBean queue = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true); ObjectName slowConsumerPolicyMBeanName = queue.getSlowConsumerStrategy(); assertNotNull(slowConsumerPolicyMBeanName); AbortSlowConsumerStrategyViewMBean abortPolicy = (AbortSlowConsumerStrategyViewMBean) broker.getManagementContext().newProxyInstance(slowConsumerPolicyMBeanName, AbortSlowConsumerStrategyViewMBean.class, true); TimeUnit.SECONDS.sleep(3); TabularData slowOnes = abortPolicy.getSlowConsumers(); assertEquals("one slow consumers", 1, slowOnes.size()); LOG.info("slow ones:" + slowOnes); CompositeData slowOne = (CompositeData) slowOnes.values().iterator().next(); LOG.info("Slow one: " + slowOne); assertTrue("we have an object name", slowOne.get("subscription") instanceof ObjectName); abortPolicy.abortConsumer((ObjectName) slowOne.get("subscription")); consumertoAbort.getValue().assertAtMostMessagesReceived(1); slowOnes = abortPolicy.getSlowConsumers(); assertEquals("no slow consumers left", 0, slowOnes.size()); // verify mbean gone with destination broker.getAdminView().removeTopic(amqDest.getPhysicalName()); try { abortPolicy.getSlowConsumers(); fail("expect not found post destination removal"); } catch (UndeclaredThrowableException expected) { assertTrue("correct exception: " + expected.getCause(), expected.getCause() instanceof InstanceNotFoundException); } }
Example 8
Source File: AbortSlowConsumer0Test.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testAbortConsumerOnDeadConnection() throws Exception { TransportConnector transportConnector = broker.addConnector("tcp://0.0.0.0:0"); transportConnector.setBrokerService(broker); transportConnector.setTaskRunnerFactory(broker.getTaskRunnerFactory()); transportConnector.start(); SocketProxy socketProxy = new SocketProxy(transportConnector.getPublishableConnectURI()); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(socketProxy.getUrl()); ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy(); prefetchPolicy.setAll(4); connectionFactory.setPrefetchPolicy(prefetchPolicy); Connection c = connectionFactory.createConnection(); connections.add(c); c.start(); Session session = c.createSession(false, Session.CLIENT_ACKNOWLEDGE); final ActiveMQMessageConsumer messageconsumer = (ActiveMQMessageConsumer) session.createConsumer(destination); startProducers(destination, 10); messageconsumer.receive(4000).acknowledge(); assertNotNull(messageconsumer.receive(4000)); assertNotNull(messageconsumer.receive(4000)); assertNotNull(messageconsumer.receive(4000)); // close control command won't get through socketProxy.pause(); ActiveMQDestination amqDest = (ActiveMQDestination) destination; ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost"); final DestinationViewMBean destView = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true); assertTrue("Consumer gone from broker view", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { LOG.info("DestView {} consumerCount {}", destView, destView.getConsumerCount()); return 0 == destView.getConsumerCount(); } })); socketProxy.goOn(); assertTrue("consumer was closed", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { boolean closed = false; try { messageconsumer.receive(400); } catch (javax.jms.IllegalStateException expected) { closed = expected.toString().contains("closed"); } return closed; } })); }