本文整理汇总了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);
}
示例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);
}
示例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);
}
}
示例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);
}
}