List of usage examples for javax.jms TopicSession createTopic
Topic createTopic(String topicName) throws JMSException;
From source file:org.wso2.carbon.event.core.internal.delivery.jms.JMSDeliveryManager.java
public void subscribe(Subscription subscription) throws EventBrokerException { if (isDeactivated()) { return;// w w w . j av a 2 s . c om } // in a multi tenant envirionment deployment synchronizer may creates subscriptions before // the event observer get activated. if (this.subscriptionIDSessionDetailsMap.containsKey(subscription.getId())) { log.warn( "There is an subscription already exists for the subscription with id " + subscription.getId()); return; } JMSMessageListener jmsMessageListener = new JMSMessageListener(this.notificationManager, subscription); try { TopicConnection topicConnection = getTopicConnection(subscription.getOwner()); TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); String topicName = ""; if (subscription.getTenantDomain() != null && (!subscription.getTenantDomain() .equals(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME))) { if (!subscription.getTopicName().startsWith("/")) { topicName = getTopicName(subscription.getTenantDomain() + "/" + subscription.getTopicName()); } else { topicName = getTopicName(subscription.getTenantDomain() + subscription.getTopicName()); } } else { topicName = getTopicName(subscription.getTopicName()); } 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); } TopicSubscriber topicSubscriber = topicSession.createDurableSubscriber(topic, subscription.getId()); topicSubscriber.setMessageListener(jmsMessageListener); this.subscriptionIDSessionDetailsMap.put(subscription.getId(), new JMSSubscriptionDetails(topicSubscriber, topicSession, topicConnection)); } catch (JMSException e) { throw new EventBrokerException( "Can not subscribe to topic " + subscription.getTopicName() + " " + e.getMessage(), e); } }
From source file:org.wso2.carbon.event.core.internal.delivery.jms.JMSDeliveryManager.java
public void publish(Message message, String topicName, int deliveryMode) throws EventBrokerException { if (isDeactivated()) { return;// ww w . ja v a 2 s. c o m } 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))) { if (!topicName.startsWith("/")) { topicName = getTopicName(tenantDomain + "/" + topicName); } else { topicName = getTopicName(tenantDomain + 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().toString()); Map<String, String> properties = message.getProperties(); for (String key : properties.keySet()) { textMessage.setStringProperty(key, properties.get(key)); } // 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); } }