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


Java TopicPublisher.setDeliveryMode方法代码示例

本文整理汇总了Java中javax.jms.TopicPublisher.setDeliveryMode方法的典型用法代码示例。如果您正苦于以下问题:Java TopicPublisher.setDeliveryMode方法的具体用法?Java TopicPublisher.setDeliveryMode怎么用?Java TopicPublisher.setDeliveryMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jms.TopicPublisher的用法示例。


在下文中一共展示了TopicPublisher.setDeliveryMode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPersistentMessagesForTopicDropped

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
/**
 * Topics shouldn't hold on to messages if there are no subscribers
 */
@Test
public void testPersistentMessagesForTopicDropped() throws Exception {
   TopicConnection topicConn = createTopicConnection();
   TopicSession sess = topicConn.createTopicSession(true, 0);
   TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1);
   pub.setDeliveryMode(DeliveryMode.PERSISTENT);

   Message m = sess.createTextMessage("testing123");
   pub.publish(m);
   sess.commit();

   topicConn.close();

   checkEmpty(ActiveMQServerTestCase.topic1);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:19,代码来源:AcknowledgementTest.java

示例2: testPersistentMessagesForTopicDropped2

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
/**
 * Topics shouldn't hold on to messages when the non-durable subscribers close
 */
@Test
public void testPersistentMessagesForTopicDropped2() throws Exception {
   TopicConnection topicConn = createTopicConnection();
   topicConn.start();
   TopicSession sess = topicConn.createTopicSession(true, 0);
   TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1);
   TopicSubscriber sub = sess.createSubscriber(ActiveMQServerTestCase.topic1);
   pub.setDeliveryMode(DeliveryMode.PERSISTENT);

   Message m = sess.createTextMessage("testing123");
   pub.publish(m);
   sess.commit();

   // receive but rollback
   TextMessage m2 = (TextMessage) sub.receive(3000);

   ProxyAssertSupport.assertNotNull(m2);
   ProxyAssertSupport.assertEquals("testing123", m2.getText());

   sess.rollback();

   topicConn.close();

   checkEmpty(ActiveMQServerTestCase.topic1);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:29,代码来源:AcknowledgementTest.java

示例3: publishTextMsg2Topic

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
/**
 * Product message for assigned topic.
 * 
 * @param uri
 *            e.g.: tcp://3CNL12096:61616
 * @param queueName
 *            name of queue
 * @throws JMSException
 */
public static void publishTextMsg2Topic(String uri, String topicName, String text) throws JMSException {
	TopicConnectionFactory connectionFactory = null;
	TopicConnection connection = null;
	TopicSession session = null;
	TopicPublisher tp = null;
	try {
		connectionFactory = new ActiveMQConnectionFactory(uri);
		connection = connectionFactory.createTopicConnection();
		connection.start();
		session = connection.createTopicSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		tp = session.createPublisher(session.createTopic(topicName));
		tp.setDeliveryMode(DeliveryMode.PERSISTENT);
		tp.publish(session.createTextMessage(text));
		session.commit();
	} finally {
		closeQuietly(tp);
		closeQuietly(session);
		closeQuietly(connection);
	}
}
 
开发者ID:slimsymphony,项目名称:testgrid,代码行数:30,代码来源:MsgUtils.java

示例4: publish

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void publish(Message message, String topicName, int deliveryMode) throws EventBrokerException {

    if (isDeactivated()){
        return;
    }

    try {
        String userName = getLoggedInUserName();
        if ((userName == null) || (userName.equals(""))) {
            // use the system user name
            userName = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
        }

        TopicConnection topicConnection = getTopicConnection(userName);
        TopicSession topicSession =
                topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        String tenantDomain= EventBrokerHolder.getInstance().getTenantDomain();
        if (tenantDomain != null && (!tenantDomain.equals(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME))) {
            topicName = tenantDomain + "/" + getTopicName(topicName);
        } else {
            topicName = getTopicName(topicName);
        }

        Topic topic = topicSession.createTopic(topicName);
        //Some times we are not getting the proper topic with the required syntax, if it is not
        //appropriate we need to check and add the BURL syntax to fix the issue https://wso2.org/jira/browse/MB-185
        if (!topic.toString().startsWith("topic://amq.topic")) {
            topic = topicSession.createTopic("BURL:" + topicName);
        }
        TopicPublisher topicPublisher = topicSession.createPublisher(topic);
        topicPublisher.setDeliveryMode(deliveryMode);
        TextMessage textMessage =
                topicSession.createTextMessage(message.getMessage());

        Map<String, String> properties = message.getProperties();
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            textMessage.setStringProperty(entry.getKey(), entry.getValue());
        }

        // saving the domain to be used send with the soap header
        if (CarbonContext.getThreadLocalCarbonContext().getTenantDomain() != null){
            textMessage.setStringProperty(MultitenantConstants.TENANT_DOMAIN_HEADER_NAME,
                                        CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
        }

        topicPublisher.publish(textMessage);
        topicPublisher.close();
        topicSession.close();
        topicConnection.stop();
        topicConnection.close();
    } catch (JMSException e) {
        throw new EventBrokerException("Can not publish to topic " + topicName + " " + e.getMessage(), e);
    }
}
 
开发者ID:wso2,项目名称:carbon-business-messaging,代码行数:59,代码来源:JMSDeliveryManager.java


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