當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。