public static ActiveMQDestination createDestination(String name, byte defaultType) { if (name.startsWith(QUEUE_QUALIFIED_PREFIX)) { return new ActiveMQQueue(name.substring(QUEUE_QUALIFIED_PREFIX.length())); } else if (name.startsWith(TOPIC_QUALIFIED_PREFIX)) { return new ActiveMQTopic(name.substring(TOPIC_QUALIFIED_PREFIX.length())); } else if (name.startsWith(TEMP_QUEUE_QUALIFED_PREFIX)) { return new ActiveMQTempQueue(name.substring(TEMP_QUEUE_QUALIFED_PREFIX.length())); } else if (name.startsWith(TEMP_TOPIC_QUALIFED_PREFIX)) { return new ActiveMQTempTopic(name.substring(TEMP_TOPIC_QUALIFED_PREFIX.length())); } switch (defaultType) { case QUEUE_TYPE: return new ActiveMQQueue(name); case TOPIC_TYPE: return new ActiveMQTopic(name); case TEMP_QUEUE_TYPE: return new ActiveMQTempQueue(name); case TEMP_TOPIC_TYPE: return new ActiveMQTempTopic(name); default: throw new IllegalArgumentException("Invalid default destination type: " + defaultType); } }
public String getTopicName() throws JMSException { return getPhysicalName(); }
Destination dest = new ActiveMQTopic(topicName); MessageConsumer nolocalConsumer = session.createConsumer(dest, null, true); MessageConsumer consumer = session.createConsumer(dest, null, false); MessageConsumer selectorConsumer = session.createConsumer(dest,"TESTKEY = 'test'", false); MessageProducer producer = session.createProducer(dest); final String body2 = "MfromAMQ-2"; TextMessage msg = session.createTextMessage(body1); producer.send(msg); msg = session.createTextMessage(body2); msg.setStringProperty("TESTKEY", "test"); producer.send(msg); TextMessage receivedMsg = (TextMessage) nolocalConsumer.receive(1000); assertNull("nolocal consumer got: " + receivedMsg, receivedMsg); receivedMsg = (TextMessage) consumer.receive(1000); assertNotNull(receivedMsg); assertEquals(body1, receivedMsg.getText()); Session anotherSession = anotherConn.createSession(false, Session.AUTO_ACKNOWLEDGE); assertNotNull(consumer.receive(1000));
public static void main(String[] args) throws Exception { Topic request = new ActiveMQTopic("request"); for (int i = 0; i < 100; i++) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml"); EchoMessageListener messageListener = ctx.getBean(EchoMessageListener.class); conn = connFactory.createConnection(); requestSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer requestConsumer = requestSession.createConsumer(request); requestConsumer.setMessageListener(messageListener); conn.start(); } finally { if( requestSession != null ) { requestSession.close(); conn.close();
Destination dest = new ActiveMQTopic(topicName); MessageConsumer consumer1 = session.createConsumer(dest); MessageConsumer consumer2 = session.createConsumer(dest); MessageProducer producer = session.createProducer(dest); for (int i = 0; i < num; i++) { TextMessage msg = session.createTextMessage("MfromAMQ-" + i); producer.send(msg); System.out.println("Sent a message"); TextMessage msg = (TextMessage) consumer1.receive(5000); System.out.println("received: " + msg); String content = msg.getText(); assertNull(consumer1.receive(500)); TextMessage msg = (TextMessage) consumer2.receive(5000); System.out.println("received: " + msg); String content = msg.getText();
map.put(new ActiveMQTopic(">"), topicPolicy); map.put(new ActiveMQQueue(">"), queuePolicy); ActiveMQQueue queue = new ActiveMQQueue("TEST"); ActiveMQTopic topic = new ActiveMQTopic("TESTTOPIC"); this.makeSureCoreQueueExist("TEST"); MessageProducer producer = session.createProducer(null); producer.setDeliveryMode(DeliveryMode.PERSISTENT); MessageConsumer queueConsumer = session.createConsumer(queue); MessageConsumer topicConsumer = session.createDurableSubscriber(topic, "tp1"); m = (TextMessage) queueConsumer.receive(100); assertNotNull(m); assertEquals("1st", m.getText()); m = (TextMessage) topicConsumer.receive(100); assertNotNull(m); assertEquals("1st", m.getText()); m = (TextMessage) queueConsumer.receive(100); assertNotNull(m); assertEquals("2nd", m.getText());
@Override public ForkliftProducerI getTopicProducer(String name) { try { final Session s = getSession(); return new ActiveMQProducer(s.createProducer(new ActiveMQTopic(name)), s); } catch (JMSException | ConnectorException e) { log.error("getTopicProducer, throwing error", e); return null; } }
@Override public void sendMessage(final String destination, final Integer pattern, final byte[] message) { Destination queue = new ActiveMQQueue(destination); if (Objects.equals(P2P.getCode(), pattern)) { queue = new ActiveMQQueue(destination); } else if (Objects.equals(TOPIC.getCode(), pattern)) { queue = new ActiveMQTopic(destination); } jmsTemplate.convertAndSend(queue, message); }
@Before public void setup() { ActiveMqTestUtils.prepare(); ActiveMQConnectionFactory targetConnectionFactory = new ActiveMQConnectionFactory(); targetConnectionFactory.setBrokerURL("vm://localhost?broker.persistent=false"); targetConnectionFactory.setTrustAllPackages(true); this.connectionFactory = new CachingConnectionFactory(targetConnectionFactory); this.topic = new ActiveMQTopic("testTopic"); this.queue = new ActiveMQQueue("testQueue"); }
public static ActiveMQTopic getSlowConsumerAdvisoryTopic(ActiveMQDestination destination) { String name = SLOW_CONSUMER_TOPIC_PREFIX + destination.getDestinationTypeAsString() + "." + destination.getPhysicalName(); return new ActiveMQTopic(name); }
public static ActiveMQTopic getExpiredTopicMessageAdvisoryTopic(ActiveMQDestination destination) { String name = EXPIRED_TOPIC_MESSAGES_TOPIC_PREFIX + destination.getPhysicalName(); return new ActiveMQTopic(name); }
protected ActiveMQDestination createDestination(Message message, String prefix, String suffix, boolean useQueue, Subscription subscription ) { String name = null; Destination regionDestination = (Destination) message.getRegionDestination(); if (regionDestination != null && regionDestination.getActiveMQDestination() != null && regionDestination.getActiveMQDestination().getPhysicalName() != null && !regionDestination.getActiveMQDestination().getPhysicalName().isEmpty()){ name = prefix + regionDestination.getActiveMQDestination().getPhysicalName(); } else { name = prefix + message.getDestination().getPhysicalName(); } if (destinationPerDurableSubscriber && subscription instanceof DurableTopicSubscription) { name += "." + ((DurableTopicSubscription)subscription).getSubscriptionKey(); } if (suffix != null && !suffix.isEmpty()) { name += suffix; } if (useQueue) { return new ActiveMQQueue(name); } else { return new ActiveMQTopic(name); } }
@Override public ActiveMQDestination onSend(String topicName) { ActiveMQTopic topic = new ActiveMQTopic(topicName); if (topic.isComposite()) { ActiveMQDestination[] composites = topic.getCompositeDestinations(); for (ActiveMQDestination composite : composites) { composite.setPhysicalName(prefix(composite.getPhysicalName())); } ActiveMQTopic result = new ActiveMQTopic(); result.setCompositeDestinations(composites); return result; } else { return new ActiveMQTopic(prefix(topicName)); } }
/** * @return a new object instance */ public DataStructure createObject() { return new ActiveMQTopic(); }
void buildDestinations(final List<JmsMock> mocks) throws MockServerException { logger.debug("buildDestinations called"); synchronized (monitor) { mocks.forEach(mock -> { if (JmsMockTypeEnum.QUEUE.equals(mock.getJmsType())) { broker.setDestinations(new ActiveMQDestination[] { new ActiveMQQueue(buildJmsUserPath(mock)) }); } else if (JmsMockTypeEnum.TOPIC.equals(mock.getJmsType())) { broker.setDestinations(new ActiveMQDestination[] { new ActiveMQTopic(buildJmsUserPath(mock)) }); } }); } }
protected void unregisterSubscription(ObjectName key, boolean addToInactive) throws Exception { queueSubscribers.remove(key); topicSubscribers.remove(key); temporaryQueueSubscribers.remove(key); temporaryTopicSubscribers.remove(key); if (registeredMBeans.remove(key)) { try { managementContext.unregisterMBean(key); } catch (Throwable e) { LOG.warn("Failed to unregister MBean {}", key); LOG.debug("Failure reason: ", e); } } DurableSubscriptionView view = (DurableSubscriptionView)durableTopicSubscribers.remove(key); if (view != null) { // need to put this back in the inactive list SubscriptionKey subscriptionKey = new SubscriptionKey(view.getClientId(), view.getSubscriptionName()); if (addToInactive) { SubscriptionInfo info = new SubscriptionInfo(); info.setClientId(subscriptionKey.getClientId()); info.setSubscriptionName(subscriptionKey.getSubscriptionName()); info.setDestination(new ActiveMQTopic(view.getDestinationName())); info.setSelector(view.getSelector()); addInactiveSubscription(subscriptionKey, info, (brokerService.isKeepDurableSubsActive() ? view.subscription : null)); } } }
postfix = postfix.substring(1, postfix.length()); ActiveMQDestination prefixDestination = prefix.length() > 0 ? new ActiveMQTopic(prefix) : null; ActiveMQDestination postfixDestination = postfix.length() > 0 ? new ActiveMQTopic(postfix) : null; String[] prefixPaths = prefixDestination != null ? prefixDestination.getDestinationPaths() : new String[] {}; String[] activeMQDestPaths = activeMQDest.getDestinationPaths(); String[] postfixPaths = postfixDestination != null ? postfixDestination.getDestinationPaths() : new String[] {}; activeMQDestPaths.length - postfixPaths.length); ActiveMQTopic newTopic = new ActiveMQTopic(DestinationPath.toString(topicPath)); info.setDestination(newTopic);
private void internalSend(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { if (!StringUtils.containsNone(messageSend.getDestination().getPhysicalName(), '+', '#')) { String message = MessageFormat.format("The caracters '+' and '#' cannot be included in a topic! Destination: {0}", messageSend.getDestination()); throw new SecurityException(message); if (!messageSend.getDestination().isTemporary()) { Set<?> allowedACLs = kapuaSecurityContext.getAuthorizationMap().getWriteACLs(messageSend.getDestination()); if (allowedACLs != null && !kapuaSecurityContext.isInOneOf(allowedACLs)) { if (destination instanceof ActiveMQTopic) { ActiveMQTopic destinationTopic = (ActiveMQTopic) destination; messageSend.setProperty(MessageConstants.PROPERTY_ORIGINAL_TOPIC, destinationTopic.getTopicName().substring(VT_TOPIC_PREFIX.length()));
public ActiveMQTopic toActiveMQTopic(List<TopicExpressionType> topics) throws InvalidTopicException { if (topics == null || topics.isEmpty()) { return null; } int size = topics.size(); ActiveMQTopic[] childrenDestinations = new ActiveMQTopic[size]; for (int i = 0; i < size; i++) { childrenDestinations[i] = toActiveMQTopic(topics.get(i)); } ActiveMQTopic topic = new ActiveMQTopic(); topic.setCompositeDestinations(childrenDestinations); return topic; }
jsonMap.put("name", dest.getQueueName()); String json = mapper.writeValueAsString(jsonMap); System.out.println(json); jsonMap.put("name", sub.getClientId() + ":" + sub.getSubscriptionName()); HashMap<String, Object> jsonTopic = new HashMap<String, Object>(); jsonTopic.put("name", dest.getTopicName()); jsonMap.put("topics", new Object[]{jsonTopic}); if (sub.getSelector() != null) {