本文整理汇总了Java中org.apache.activemq.command.ActiveMQTopic类的典型用法代码示例。如果您正苦于以下问题:Java ActiveMQTopic类的具体用法?Java ActiveMQTopic怎么用?Java ActiveMQTopic使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ActiveMQTopic类属于org.apache.activemq.command包,在下文中一共展示了ActiveMQTopic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: export
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
@Override
public void export() throws IOException {
store.getDestinations().stream()
.forEach(dest -> {
try {
if (dest.isQueue()) {
xmlMarshaller.appendBinding(QueueBindingType.builder()
.withName(dest.getPhysicalName())
.withRoutingType(RoutingType.ANYCAST.toString())
.withAddress(dest.getPhysicalName()).build());
} else if (dest.isTopic()) {
for (SubscriptionInfo info :
store.createTopicMessageStore((ActiveMQTopic) dest).getAllSubscriptions()) {
xmlMarshaller.appendBinding(QueueBindingType.builder()
.withName(ActiveMQDestination.createQueueNameForDurableSubscription(
true, info.getClientId(), info.getSubcriptionName()))
.withRoutingType(RoutingType.MULTICAST.toString())
.withAddress(dest.getPhysicalName()).build());
}
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
});
}
示例2: testTopicWithStoreNoSubscriptions
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
@Test
public void testTopicWithStoreNoSubscriptions() throws Exception {
String topicName = "test.topic";
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText("test");
message.setDestination(new ActiveMQTopic(topicName));
message.setMessageId(new MessageId(id.generateId() + ":1", 0));
TopicMessageStore ms = adapter.createTopicMessageStore(new ActiveMQTopic(topicName));
ms.addMessage(context, message);
OpenWireCoreMessageTypeConverter c = new OpenWireCoreMessageTypeConverter(store);
MessageType messageType = c.convert(message);
assertEquals(XmlDataConstants.TEXT_TYPE_PRETTY, messageType.getType());
assertTrue(messageType.getQueues().getQueue().isEmpty());
}
示例3: testTopicWithStoreOneSub
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
@Test
public void testTopicWithStoreOneSub() throws Exception {
String topicName = "test.topic";
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText("test");
message.setDestination(new ActiveMQTopic(topicName));
message.setMessageId(new MessageId(id.generateId() + ":1", 0));
TopicMessageStore ms = adapter.createTopicMessageStore(new ActiveMQTopic(topicName));
ms.addSubscription(new SubscriptionInfo("clientId", "subName"), false);
ms.addMessage(context, message);
OpenWireCoreMessageTypeConverter c = new OpenWireCoreMessageTypeConverter(store);
MessageType messageType = c.convert(message);
assertEquals(XmlDataConstants.TEXT_TYPE_PRETTY, messageType.getType());
assertEquals(ActiveMQDestination.createQueueNameForDurableSubscription(true, "clientId", "subName"),
messageType.getQueues().getQueue().get(0).getName());
}
示例4: publish
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
@Override
public void publish(final String message, final String topicName, final long timeToLive) throws JMSException {
if (topicName == null) {
throw new NullPointerException("publish(..) method called with null queue name argument");
}
if (message == null) {
throw new NullPointerException("publish(..) method called with null message argument");
}
if (connected) {
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
final Message messageObj = session.createTextMessage(message);
final MessageProducer producer = session.createProducer(new ActiveMQTopic(topicName));
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.setTimeToLive(JMS_MESSAGE_TIMEOUT);
producer.send(messageObj);
} finally {
session.close();
}
} else {
throw new JMSException("Not currently connected: unable to send message at this time.");
}
}
示例5: startListenerThread
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
/**
* Listens for 1s for updates on the tag topic.
*/
private Thread startListenerThread(final Tag tag) {
// start listener in separate thread (to catch update to topic)
Thread listenerThread = new Thread(new Runnable() {
@Override
public void run() {
try {
JmsTemplate template = new JmsTemplate(connectionFactory);
template.setReceiveTimeout(1000);
synchronized (updateLock) {
Message message = template.receive(new ActiveMQTopic("c2mon.client.tag." + ((DataTag) tag).getProcessId()));
update = TransferTagSerializer.fromJson(((TextMessage) message).getText(), TransferTagValueImpl.class);
}
} catch (Exception e) {
synchronized (updateLock) {
update = null;
}
}
}
});
listenerThread.start();
return listenerThread;
}
示例6: startListenerThreadForTransferTag
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
/**
* Listens for 1s for updates on the tag topic.
*/
private Thread startListenerThreadForTransferTag(final Tag tag) {
// start listener in separate thread (to catch update to topic)
Thread listenerThread = new Thread(new Runnable() {
@Override
public void run() {
try {
JmsTemplate template = new JmsTemplate(connectionFactory);
template.setReceiveTimeout(5000);
synchronized (updateLock) {
Message message = template.receive(new ActiveMQTopic("c2mon.client.tag." + ((DataTag) tag).getProcessId()));
updateFromConfig = TransferTagSerializer.fromJson(((TextMessage) message).getText(), TransferTagImpl.class);
}
} catch (Exception e) {
synchronized (updateLock) {
updateFromConfig = null;
}
}
}
});
listenerThread.start();
return listenerThread;
}
示例7: TestLifeCycle
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
@Inject
public TestLifeCycle(JmsConnection jmsConnection, Destination resultsDestination,
SuiteExecutor suiteExecutor,
SuiteIndexWrapper suite)
throws JMSException {
this.suiteExecutor = suiteExecutor;
this.suite = suite;
if (resultsDestination instanceof ActiveMQDestination) {
ActiveMQTopic advisoryTopic = AdvisorySupport.getConsumerAdvisoryTopic(resultsDestination);
session = jmsConnection.getJmsSession();
topicConsumer = session.createConsumer(advisoryTopic);
topicConsumer.setMessageListener(this);
} else {
topicConsumer = null;
session = null;
}
}
示例8: setUp
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
brokerService = createBroker();
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("vm://localhost");
activeMQConnectionFactory.setWatchTopicAdvisories(true);
connection = activeMQConnectionFactory.createConnection();
connection.setClientID("ClientID-1");
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = new ActiveMQTopic(TOPIC_NAME);
producer = session.createProducer(destination);
connection.start();
}
示例9: testConnectorConfiguredCorrectly
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
public void testConnectorConfiguredCorrectly() throws Exception {
TransportConnector connector = brokerService.getTransportConnectors().get(0);
assertEquals(new URI("tcp://localhost:61636"), connector.getUri());
assertTrue(connector.getTaskRunnerFactory() == brokerService.getTaskRunnerFactory());
NetworkConnector netConnector = brokerService.getNetworkConnectors().get(0);
List<ActiveMQDestination> excludedDestinations = netConnector.getExcludedDestinations();
assertEquals(new ActiveMQQueue("exclude.test.foo"), excludedDestinations.get(0));
assertEquals(new ActiveMQTopic("exclude.test.bar"), excludedDestinations.get(1));
List<ActiveMQDestination> dynamicallyIncludedDestinations = netConnector.getDynamicallyIncludedDestinations();
assertEquals(new ActiveMQQueue("include.test.foo"), dynamicallyIncludedDestinations.get(0));
assertEquals(new ActiveMQTopic("include.test.bar"), dynamicallyIncludedDestinations.get(1));
}
示例10: setupTopicProducer
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
/**
* Create a {@link MessageProducer} for a given destination queue.
*
* @param destination the {@link Queue} to use
* @return a configured {@link MessageProducer} or null if there were errors
*/
public synchronized MessageProducer setupTopicProducer(final String destination) {
this.checkAllowedState(State.SESSION_ACTIVE);
final Destination dest = new ActiveMQTopic(destination);
MessageProducer producer = null;
try {
producer = this.session.createProducer(dest);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
catch (final JMSException ex) {
LOGGER.error("Problems during setup of TopicProducer.", ex);
this.state = State.FAILURE;
}
return producer;
}
示例11: removeDestination
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
@Override
public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception {
super.removeDestination(context, destination, timeout);
DestinationInfo info = destinations.remove(destination);
if (info != null) {
// ensure we don't modify (and loose/overwrite) an in-flight add advisory, so duplicate
info = info.copy();
info.setDestination(destination);
info.setOperationType(DestinationInfo.REMOVE_OPERATION_TYPE);
ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destination);
fireAdvisory(context, topic, info);
ActiveMQTopic[] advisoryDestinations = AdvisorySupport.getAllDestinationAdvisoryTopics(destination);
for(ActiveMQTopic advisoryDestination : advisoryDestinations) {
try {
next.removeDestination(context, advisoryDestination, -1);
} catch (Exception expectedIfDestinationDidNotExistYet) {
}
}
}
}
示例12: removeDestinationInfo
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
@Override
public void removeDestinationInfo(ConnectionContext context, DestinationInfo destInfo) throws Exception {
super.removeDestinationInfo(context, destInfo);
DestinationInfo info = destinations.remove(destInfo.getDestination());
if (info != null) {
// ensure we don't modify (and loose/overwrite) an in-flight add advisory, so duplicate
info = info.copy();
info.setDestination(destInfo.getDestination());
info.setOperationType(DestinationInfo.REMOVE_OPERATION_TYPE);
ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destInfo.getDestination());
fireAdvisory(context, topic, info);
ActiveMQTopic[] advisoryDestinations = AdvisorySupport.getAllDestinationAdvisoryTopics(destInfo.getDestination());
for(ActiveMQTopic advisoryDestination : advisoryDestinations) {
try {
next.removeDestination(context, advisoryDestination, -1);
} catch (Exception expectedIfDestinationDidNotExistYet) {
}
}
}
}
示例13: setUp
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
localConnectionFactory = createLocalConnectionFactory();
foreignConnectionFactory = createForeignConnectionFactory();
outbound = new ActiveMQTopic("RECONNECT.TEST.OUT.TOPIC");
inbound = new ActiveMQTopic("RECONNECT.TEST.IN.TOPIC");
jmsTopicConnector = new SimpleJmsTopicConnector();
// Wire the bridges.
jmsTopicConnector.setOutboundTopicBridges(new OutboundTopicBridge[]{new OutboundTopicBridge("RECONNECT.TEST.OUT.TOPIC")});
jmsTopicConnector.setInboundTopicBridges(new InboundTopicBridge[]{new InboundTopicBridge("RECONNECT.TEST.IN.TOPIC")});
// Tell it how to reach the two brokers.
jmsTopicConnector.setOutboundTopicConnectionFactory(new ActiveMQConnectionFactory("tcp://localhost:61617"));
jmsTopicConnector.setLocalTopicConnectionFactory(new ActiveMQConnectionFactory("tcp://localhost:61616"));
}
示例14: setupTopicListener
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
/**
* Create A Consumer for the given Topic and set the given
* {@link MessageListener}.
*
* @param topic The {@link Topic} to use
* @param listener The {@link MessageListener} to set
* @return true means failure
*/
public synchronized boolean setupTopicListener(final String topic, final MessageListener listener) {
this.checkAllowedState(State.SESSION_ACTIVE);
final ActiveMQTopic top = new ActiveMQTopic(topic);
MessageConsumer consumer;
try {
consumer = this.session.createConsumer(top);
consumer.setMessageListener(listener);
}
catch (final JMSException ex) {
LOGGER.error("Problems during setup of TopicListener.", ex);
this.state = State.FAILURE;
return true;
}
return false;
}
示例15: messageDiscarded
import org.apache.activemq.command.ActiveMQTopic; //导入依赖的package包/类
@Override
public void messageDiscarded(ConnectionContext context, Subscription sub, MessageReference messageReference) {
super.messageDiscarded(context, sub, messageReference);
try {
if (!messageReference.isAdvisory()) {
ActiveMQTopic topic = AdvisorySupport.getMessageDiscardedAdvisoryTopic(messageReference.getMessage().getDestination());
Message payload = messageReference.getMessage().copy();
payload.clearBody();
ActiveMQMessage advisoryMessage = new ActiveMQMessage();
if (sub instanceof TopicSubscription) {
advisoryMessage.setIntProperty(AdvisorySupport.MSG_PROPERTY_DISCARDED_COUNT, ((TopicSubscription)sub).discarded());
}
advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_CONSUMER_ID, sub.getConsumerInfo().getConsumerId().toString());
fireAdvisory(context, topic, payload, null, advisoryMessage);
}
} catch (Exception e) {
handleFireFailure("discarded", e);
}
}