当前位置: 首页>>代码示例>>Java>>正文


Java Topic类代码示例

本文整理汇总了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);
		}
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:23,代码来源:JmsClient.java

示例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();
}
 
开发者ID:SolaceLabs,项目名称:solace-integration-guides,代码行数:20,代码来源:JMSPublisherConsumerTest.java

示例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();
}
 
开发者ID:sventorben,项目名称:axon-jms,代码行数:17,代码来源:JmsPublisherTest.java

示例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);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:22,代码来源:JmsClient.java

示例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) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:17,代码来源:JmsPoolTopicSubscriberTest.java

示例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) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:18,代码来源:JmsPoolTopicPublisherTest.java

示例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();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:20,代码来源:JMSPublisherConsumerTest.java

示例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();
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:10,代码来源:TestEEfiSession.java

示例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();
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:10,代码来源:TestEEfiSession.java

示例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;
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:12,代码来源:JmsPoolSession.java

示例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);
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:9,代码来源:JMSContextImpl.java

示例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);
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:9,代码来源:JmsPoolJMSContext.java

示例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);
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:9,代码来源:JMSContextImpl.java

示例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));
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:9,代码来源:ManagedQueueTopicSession.java

示例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();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:41,代码来源:JMSMessageConsumerTestBase.java


注:本文中的javax.jms.Topic类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。