Refine search
private String retrieveDestinationName(Destination destination, String headerName) { String destinationName = null; if (destination != null) { try { destinationName = (destination instanceof Queue) ? ((Queue) destination).getQueueName() : ((Topic) destination).getTopicName(); } catch (JMSException e) { this.processLog.warn("Failed to retrieve Destination name for '" + headerName + "' header", e); } } return destinationName; }
@Override public MessageConsumer createSharedDurableConsumer(Topic topic, String name, String messageSelector) throws JMSException { if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot create a shared durable consumer on a QueueSession"); } checkTopic(topic); ActiveMQTopic localTopic; if (topic instanceof ActiveMQTopic) { localTopic = (ActiveMQTopic) topic; } else { localTopic = new ActiveMQTopic(topic.getTopicName()); } return internalCreateSharedConsumer(localTopic, name, messageSelector, ConsumerDurability.DURABLE); }
public TopicExpressionType toTopicExpression(Topic topic) { return toTopicExpression(topic.toString()); }
@Override public MessageConsumer createDurableConsumer(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException { if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot create a durable consumer on a QueueSession"); } checkTopic(topic); ActiveMQTopic localTopic; if (topic instanceof ActiveMQTopic) { localTopic = (ActiveMQTopic) topic; } else { localTopic = new ActiveMQTopic(topic.getTopicName()); } return createConsumer(localTopic, name, messageSelector, noLocal, ConsumerDurability.DURABLE); }
void tagQueueOrTopic(Destination destination, SpanCustomizer span) { try { if (destination instanceof Queue) { span.tag(JMS_QUEUE, ((Queue) destination).getQueueName()); } else if (destination instanceof Topic) { span.tag(JMS_TOPIC, ((Topic) destination).getTopicName()); } } catch (JMSException ignored) { // don't crash on wonky exceptions! } } }
/** * Note: Needs to throw an exception if a subscriptionName is already in use by another topic, or if the messageSelector is different * * validate multiple subscriptions on the same session. * validate multiple subscriptions on different sessions * validate failure in one connection while another connection stills fine. * Validate different filters in different possible scenarios * * @param topic * @param name * @param messageSelector * @return * @throws JMSException */ @Override public MessageConsumer createSharedConsumer(Topic topic, String name, String messageSelector) throws JMSException { if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot create a shared consumer on a QueueSession"); } checkTopic(topic); ActiveMQTopic localTopic; if (topic instanceof ActiveMQTopic) { localTopic = (ActiveMQTopic) topic; } else { localTopic = new ActiveMQTopic(topic.getTopicName()); } return internalCreateSharedConsumer(localTopic, name, messageSelector, ConsumerDurability.NON_DURABLE); }
@Override public ActiveMQDestination transform(Destination dest) throws JMSException { String queueName = ((Queue) dest).getQueueName(); String topicName = ((Topic) dest).getTopicName(); if (queueName == null && topicName == null) { throw new JMSException("Unresolvable destination: Both queue and topic names are null: " + dest); } try { Method isQueueMethod = dest.getClass().getMethod("isQueue"); Method isTopicMethod = dest.getClass().getMethod("isTopic"); Boolean isQueue = (Boolean) isQueueMethod.invoke(dest); Boolean isTopic = (Boolean) isTopicMethod.invoke(dest); if (isQueue) { return new ActiveMQQueue(queueName); } else if (isTopic) { return new ActiveMQTopic(topicName); } else { throw new JMSException("Unresolvable destination: Neither Queue nor Topic: " + dest); } } catch (Exception e) { throw new JMSException("Unresolvable destination: " + e.getMessage() + ": " + dest); } }
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()); }
String destinationName; if (message.getJMSDestination() instanceof Queue) { destinationName = ((Queue) message.getJMSDestination()).getQueueName(); } else { destinationName = ((Topic) message.getJMSDestination()).getTopicName();
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()); }
String queueName = ((Queue) dest).getQueueName(); String topicName = ((Topic) dest).getTopicName(); if (queueName != null && topicName == null) { return new ActiveMQQueue(queueName); return new ActiveMQQueue(((Queue) dest).getQueueName()); return new ActiveMQTopic(((Topic) dest).getTopicName());
public void testInterceptorAll() throws Exception { MessageInterceptorRegistry registry = MessageInterceptorRegistry.getInstance().get(BrokerRegistry.getInstance().findFirst()); registry.addMessageInterceptorForTopic(topic.getTopicName(), new MessageInterceptor() { @Override public void intercept(ProducerBrokerExchange producerExchange, Message message) { //just ignore } }); 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(messageCount,latch.getCount()); }
private String getDestinationAsString(Destination destination) throws JMSException { String result = null; if (destination == null) { result = "null destination!" + File.separator; } else if (destination instanceof Topic) { result = "topic" + File.separator + ((Topic) destination).getTopicName() + File.separator; } else if (destination instanceof Queue) { result = "queue" + File.separator + ((Queue) destination).getQueueName() + File.separator; } return result; }
public void testNoStackOverFlow() throws Exception { final MessageInterceptorRegistry registry = MessageInterceptorRegistry.getInstance().get(BrokerRegistry.getInstance().findFirst()); registry.addMessageInterceptorForTopic(topic.getTopicName(), new MessageInterceptor() { @Override public void intercept(ProducerBrokerExchange producerExchange, Message message) { try { registry.injectMessage(producerExchange, message); } catch (Exception e) { e.printStackTrace(); } } }); 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()); }
protected void setFromName(Destination destination, boolean queue) { try { fromName = queue ? "queue/" + ((Queue)destination).getQueueName() : "topic/" + ((Topic)destination).getTopicName(); } catch (JMSException e) { throw new RuntimeException(e); } }
public JMSTopicSink(String tcfBindingName, String topicBindingName, String username, String password) { try { Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); env.put(Context.PROVIDER_URL, "tcp://localhost:61616"); Context ctx = new InitialContext(env); TopicConnectionFactory topicConnectionFactory; topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName); System.out.println("Topic Cnx Factory found"); Topic topic = (Topic) ctx.lookup(topicBindingName); System.out.println("Topic found: " + topic.getTopicName()); TopicConnection topicConnection = topicConnectionFactory .createTopicConnection(username, password); System.out.println("Topic Connection created"); TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic); topicSubscriber.setMessageListener(this); topicConnection.start(); System.out.println("Topic Connection started"); } catch (Exception e) { logger.error("Could not read JMS message.", e); } }
/** * @param dest jms destination * @param type destination type * * @return destination name ({@link Queue#getQueueName()}, {@link Topic#getTopicName()}) * * @throws JMSException if any occurs by accessing {@code dest} properties */ static String getDestinationName(Destination dest, DestinationType type) throws JMSException { String name = UNKNOWN; switch(type) { case Queue: case TemporaryQueue: name = ((Queue) dest).getQueueName(); break; case Topic: case TemporaryTopic: name = ((Topic) dest).getTopicName(); break; default: // do nothing } return name; }
public JmsEndpoint(Topic destination) throws JMSException { this("jms:topic:" + destination.getTopicName(), null); this.destination = destination; this.destinationType = "topic"; }
private String getDestinationLabel(Destination destination) { if (destination == null) { return "null"; } try { if (destination instanceof Queue) { return "queue " +((Queue) destination).getQueueName(); } else if (destination instanceof Topic) { return "topic " +((Topic) destination).getTopicName(); } else { return "unknown destination type " + destination.toString(); } } catch (JMSException e) { logger.error("Failed to retrieve destination details {}", destination, e); } return "error retrieving destination details"; } }
TopicDestinationEndpoint(Topic topic) throws JMSException { super(topic.getTopicName()); m_topic = topic; }