本文整理汇总了Java中javax.jms.Topic类的典型用法代码示例。如果您正苦于以下问题:Java Topic类的具体用法?Java Topic怎么用?Java Topic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Topic类属于javax.jms包,在下文中一共展示了Topic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTopicConsumer
import javax.jms.Topic; //导入依赖的package包/类
public MessageConsumer createTopicConsumer(String selector) throws JMSException {
if (isQueue) {
throw new IllegalArgumentException("Only for topic, not queue");
}
String consumerId = "consumer-" + UUID.randomUUID();
topicConnection = startConnection(consumerId);
Session session = topicConnection.createSession(isTransacted, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(destinationName);
if (isDurable) {
if (selector != null) {
return session.createDurableSubscriber(topic, consumerId, selector, true);
} else {
return session.createDurableSubscriber(topic, consumerId);
}
} else {
if (selector != null) {
return session.createConsumer(topic, selector);
} else {
return session.createConsumer(topic);
}
}
}
示例2: validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes
import javax.jms.Topic; //导入依赖的package包/类
@Test
public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes() throws Exception {
final String destinationName = "testQueue";
JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
Map<String, String> flowFileAttributes = new HashMap<>();
flowFileAttributes.put("foo", "foo");
flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic");
publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes);
Message receivedMessage = jmsTemplate.receive(destinationName);
assertTrue(receivedMessage instanceof BytesMessage);
assertEquals("foo", receivedMessage.getStringProperty("foo"));
assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic);
assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName());
((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
示例3: setUp
import javax.jms.Topic; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
eventBus = new SimpleEventBus();
cut = new JmsPublisher(eventBus);
connectionFactory = mock(TopicConnectionFactory.class);
publisher = mock(TopicPublisher.class);
topic = mock(Topic.class);
converter = mock(JmsMessageConverter.class);
cut.setConnectionFactory(connectionFactory);
cut.setTopic(topic);
cut.setTransacted(true);
cut.setMessageConverter(converter);
cut.setPersistent(false);
cut.postConstruct();
cut.start();
}
示例4: createTopic
import javax.jms.Topic; //导入依赖的package包/类
/**
* Create a topic
*
* @param topicName the topic name
*/
@PublicAtsApi
public void createTopic(
final String topicName ) {
try {
final Session session = loadSession(false, Session.AUTO_ACKNOWLEDGE);
final Topic topic = session.createTopic(topicName);
session.createConsumer(topic).close();
} catch (JMSException e) {
throw new JmsMessageException("Could not start listening for messages on topic " + topicName,
e);
} finally {
releaseSession(false);
}
}
示例5: testGetNoLocal
import javax.jms.Topic; //导入依赖的package包/类
@Test
public void testGetNoLocal() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createTopicConnection();
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTemporaryTopic();
TopicSubscriber subscriber = session.createDurableSubscriber(topic, "name", "color = red", true);
assertTrue(subscriber.getNoLocal());
subscriber.close();
try {
subscriber.getNoLocal();
fail("Cannot read state on closed subscriber");
} catch (IllegalStateException ise) {}
}
示例6: testGetTopic
import javax.jms.Topic; //导入依赖的package包/类
@Test
public void testGetTopic() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createTopicConnection();
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTemporaryTopic();
TopicPublisher publisher = session.createPublisher(topic);
assertNotNull(publisher.getTopic());
assertSame(topic, publisher.getTopic());
publisher.close();
try {
publisher.getTopic();
fail("Cannot read topic on closed publisher");
} catch (IllegalStateException ise) {}
}
示例7: validateJmsHeadersAndPropertiesAreTransferredFromFFAttributesOverJNDI
import javax.jms.Topic; //导入依赖的package包/类
@Test
public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributesOverJNDI() throws Exception {
final String destinationName = "testQueue";
JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);
JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
Map<String, String> flowFileAttributes = new HashMap<>();
flowFileAttributes.put("foo", "foo");
flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic");
publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes);
Message receivedMessage = jmsTemplate.receive(destinationName);
assertTrue(receivedMessage instanceof BytesMessage);
assertEquals("foo", receivedMessage.getStringProperty("foo"));
assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic);
assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName());
((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
示例8: createDurableConsumer
import javax.jms.Topic; //导入依赖的package包/类
@Override
public MessageConsumer createDurableConsumer(
final Topic topic,
final String name,
final String messageSelector,
final boolean noLocal
) throws JMSException {
return notImplemented();
}
示例9: createDurableSubscriber
import javax.jms.Topic; //导入依赖的package包/类
@Override
public TopicSubscriber createDurableSubscriber(
final Topic topic,
final String name,
final String messageSelector,
final boolean noLocal
) throws JMSException {
return notImplemented();
}
示例10: getTopicPublisher
import javax.jms.Topic; //导入依赖的package包/类
private TopicPublisher getTopicPublisher(Topic destination) throws JMSException {
TopicPublisher result = null;
if (useAnonymousProducers) {
result = safeGetSessionHolder().getOrCreatePublisher();
} else {
result = ((TopicSession) getInternalSession()).createPublisher(destination);
}
return result;
}
示例11: createSharedDurableConsumer
import javax.jms.Topic; //导入依赖的package包/类
@Override
public JMSConsumer createSharedDurableConsumer(Topic topic, String name) {
try {
return startIfNeeded(new JMSConsumerImpl(this, getSession().createSharedDurableConsumer(topic, name)));
} catch (JMSException jmse) {
throw Utils.convertToRuntimeException(jmse);
}
}
示例12: createDurableConsumer
import javax.jms.Topic; //导入依赖的package包/类
@Override
public JMSConsumer createDurableConsumer(Topic topic, String name, String selector, boolean noLocal) {
try {
return startIfNeeded(new JmsPoolJMSConsumer((JmsPoolMessageConsumer) getSession().createDurableConsumer(topic, name, selector, noLocal)));
} catch (JMSException jmse) {
throw JMSExceptionSupport.createRuntimeException(jmse);
}
}
示例13: createDurableConsumer
import javax.jms.Topic; //导入依赖的package包/类
@Override
public JMSConsumer createDurableConsumer(Topic topic, String name, String selector, boolean noLocal) {
try {
return startIfNeeded(new JMSConsumerImpl(this, getSession().createDurableConsumer(topic, name, selector, noLocal)));
} catch (JMSException jmse) {
throw Utils.convertToRuntimeException(jmse);
}
}
示例14: createSubscriber
import javax.jms.Topic; //导入依赖的package包/类
@Override
public TopicSubscriber createSubscriber(
Topic topic,
String messageSelector,
boolean noLocal ) throws JMSException {
return addConsumer( ((TopicSession) session).createSubscriber(topic, messageSelector, noLocal));
}
示例15: setup
import javax.jms.Topic; //导入依赖的package包/类
@Before
public void setup() throws Exception {
beforeSetup();
connectionFactory = mock(ConnectionFactory.class);
connection = mock(Connection.class);
session = mock(Session.class);
queue = mock(Queue.class);
topic = mock(Topic.class);
messageConsumer = mock(MessageConsumer.class);
message = mock(TextMessage.class);
when(message.getPropertyNames()).thenReturn(new Enumeration<Object>() {
@Override
public boolean hasMoreElements() {
return false;
}
@Override
public Object nextElement() {
throw new UnsupportedOperationException();
}
});
when(message.getText()).thenReturn(TEXT);
when(connectionFactory.createConnection(USERNAME, PASSWORD)).thenReturn(connection);
when(connection.createSession(true, Session.SESSION_TRANSACTED)).thenReturn(session);
when(session.createQueue(destinationName)).thenReturn(queue);
when(session.createConsumer(any(Destination.class), anyString())).thenReturn(messageConsumer);
when(messageConsumer.receiveNoWait()).thenReturn(message);
when(messageConsumer.receive(anyLong())).thenReturn(message);
destinationName = DESTINATION_NAME;
destinationType = JMSDestinationType.QUEUE;
destinationLocator = JMSDestinationLocator.CDI;
messageSelector = SELECTOR;
batchSize = 10;
pollTimeout = 500L;
context = new Context();
converter = new DefaultJMSMessageConverter.Builder().build(context);
event = converter.convert(message).iterator().next();
userName = Optional.of(USERNAME);
password = Optional.of(PASSWORD);
afterSetup();
}