Example usage for javax.jms Session AUTO_ACKNOWLEDGE

List of usage examples for javax.jms Session AUTO_ACKNOWLEDGE

Introduction

In this page you can find the example usage for javax.jms Session AUTO_ACKNOWLEDGE.

Prototype

int AUTO_ACKNOWLEDGE

To view the source code for javax.jms Session AUTO_ACKNOWLEDGE.

Click Source Link

Document

With this acknowledgment mode, the session automatically acknowledges a client's receipt of a message either when the session has successfully returned from a call to receive or when the message listener the session has called to process the message successfully returns.

Usage

From source file:org.apache.synapse.transport.jms.JMSSender.java

/**
 * Performs the actual sending of the JMS message
 *//*from  ww  w .j  a  v a 2s. c  o  m*/
public void sendMessage(MessageContext msgCtx, String targetAddress, OutTransportInfo outTransportInfo)
        throws AxisFault {

    JMSConnectionFactory jmsConnectionFactory = null;
    Connection connection = null; // holds a one time connection if used
    JMSOutTransportInfo jmsOut = null;
    Session session = null;
    Destination destination = null;
    Destination replyDestination = null;

    try {
        if (targetAddress != null) {

            jmsOut = new JMSOutTransportInfo(targetAddress);
            // do we have a definition for a connection factory to use for this address?
            jmsConnectionFactory = getJMSConnectionFactory(jmsOut);

            if (jmsConnectionFactory != null) {
                // create new or get existing session to send to the destination from the CF
                session = jmsConnectionFactory.getSessionForDestination(JMSUtils.getDestination(targetAddress));

            } else {
                // digest the targetAddress and locate CF from the EPR
                jmsOut.loadConnectionFactoryFromProperies();
                try {
                    // create a one time connection and session to be used
                    Hashtable jndiProps = jmsOut.getProperties();
                    String user = (String) jndiProps.get(Context.SECURITY_PRINCIPAL);
                    String pass = (String) jndiProps.get(Context.SECURITY_CREDENTIALS);

                    QueueConnectionFactory qConFac = null;
                    TopicConnectionFactory tConFac = null;
                    ConnectionFactory conFac = null;

                    if (JMSConstants.DESTINATION_TYPE_QUEUE.equals(jmsOut.getDestinationType())) {
                        qConFac = (QueueConnectionFactory) jmsOut.getConnectionFactory();
                    } else if (JMSConstants.DESTINATION_TYPE_TOPIC.equals(jmsOut.getDestinationType())) {
                        tConFac = (TopicConnectionFactory) jmsOut.getConnectionFactory();
                    } else {
                        handleException(
                                "Unable to determine type of JMS " + "Connection Factory - i.e Queue/Topic");
                    }

                    if (user != null && pass != null) {
                        if (qConFac != null) {
                            connection = qConFac.createQueueConnection(user, pass);
                        } else if (tConFac != null) {
                            connection = tConFac.createTopicConnection(user, pass);
                        }
                    } else {
                        if (qConFac != null) {
                            connection = qConFac.createQueueConnection();
                        } else if (tConFac != null) {
                            connection = tConFac.createTopicConnection();
                        }
                    }

                    if (JMSConstants.DESTINATION_TYPE_QUEUE.equals(jmsOut.getDestinationType())) {
                        session = ((QueueConnection) connection).createQueueSession(false,
                                Session.AUTO_ACKNOWLEDGE);
                    } else if (JMSConstants.DESTINATION_TYPE_TOPIC.equals(jmsOut.getDestinationType())) {
                        session = ((TopicConnection) connection).createTopicSession(false,
                                Session.AUTO_ACKNOWLEDGE);
                    }

                } catch (JMSException e) {
                    handleException("Error creating a connection/session for : " + targetAddress);
                }
            }
            destination = jmsOut.getDestination();

        } else if (outTransportInfo != null && outTransportInfo instanceof JMSOutTransportInfo) {

            jmsOut = (JMSOutTransportInfo) outTransportInfo;
            jmsConnectionFactory = jmsOut.getJmsConnectionFactory();

            session = jmsConnectionFactory.getSessionForDestination(jmsOut.getDestination().toString());
            destination = jmsOut.getDestination();
        }

        String replyDestName = (String) msgCtx.getProperty(JMSConstants.JMS_REPLY_TO);
        if (replyDestName != null) {
            if (jmsConnectionFactory != null) {
                replyDestination = jmsConnectionFactory.getDestination(replyDestName);
            } else {
                replyDestination = jmsOut.getReplyDestination(replyDestName);
            }
        }

        // now we are going to use the JMS session, but if this was a session from a
        // defined JMS connection factory, we need to synchronize as sessions are not
        // thread safe
        synchronized (session) {

            // convert the axis message context into a JMS Message that we can send over JMS
            Message message = null;
            String correlationId = null;
            try {
                message = createJMSMessage(msgCtx, session);
            } catch (JMSException e) {
                handleException("Error creating a JMS message from the axis message context", e);
            }

            String destinationType = jmsOut.getDestinationType();

            // if the destination does not exist, see if we can create it
            destination = JMSUtils.createDestinationIfRequired(destination, destinationType, targetAddress,
                    session);

            // should we wait for a synchronous response on this same thread?
            boolean waitForResponse = waitForSynchronousResponse(msgCtx);

            // if this is a synchronous out-in, prepare to listen on the response destination
            if (waitForResponse) {
                replyDestination = JMSUtils.setReplyDestination(replyDestination, session, message);
            }

            // send the outgoing message over JMS to the destination selected
            JMSUtils.sendMessageToJMSDestination(session, destination, message);

            // if we are expecting a synchronous response back for the message sent out
            if (waitForResponse) {
                try {
                    connection.start();
                } catch (JMSException ignore) {
                }
                try {
                    correlationId = message.getJMSMessageID();
                } catch (JMSException ignore) {
                }
                waitForResponseAndProcess(session, replyDestination, msgCtx, correlationId);
            }
        }

    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException ignore) {
            }
        }
    }
}

From source file:com.mirth.connect.connectors.jms.JmsReceiverTests.java

@BeforeClass
public static void beforeClass() throws Exception {
    JmsReceiverProperties properties = getInitialProperties();

    if (properties.isUseJndi()) {
        connectionFactory = lookupConnectionFactoryWithJndi(properties);
    } else {/*from   w  w  w . j a  v  a  2 s.c o m*/
        String className = properties.getConnectionFactoryClass();
        connectionFactory = (ConnectionFactory) Class.forName(className).newInstance();
    }

    BeanUtils.populate(connectionFactory, properties.getConnectionProperties());

    Connection connection = connectionFactory.createConnection(properties.getUsername(),
            properties.getPassword());
    connection.start();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}

From source file:de.klemp.middleware.controller.Controller.java

/**
 * This method creates a connection to the message broker Active MQ and
 * sends the message to the given topic. The method is used by all methods
 * of the second component.//from w ww.j a  v  a 2s.c o m
 * 
 * @param message
 *            send to the output device
 * @param topic
 *            of the message broker
 */
public static void sendMessage(String message, String topic) {
    String url = ActiveMQConnection.DEFAULT_BROKER_URL;
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);

    // Create a Connection
    Connection connection;
    try {
        connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Create the destination (Topic or Queue)
        Destination destination = session.createTopic(topic);
        // Create a MessageProducer from the Session to the Topic or Queue
        MessageProducer producer = session.createProducer(destination);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        // Create a messages
        TextMessage message1 = session.createTextMessage(message);
        // Tell the producer to send the message
        producer.send(message1);
        session.close();
        connection.close();
    } catch (JMSException e) {
        logger.error("Message could not be sended to activemq", e);
    }

}

From source file:org.seedstack.ws.jms.internal.WSJmsPlugin.java

@Override
public InitState initialize(InitContext initContext) {
    jmsPlugin = initContext.dependency(JmsPlugin.class);
    WSPlugin wsPlugin = initContext.dependency(WSPlugin.class);
    final WebServicesJmsConfig webServicesJmsConfig = getConfiguration(WebServicesJmsConfig.class);

    WebServicesJmsConfig.JmsConfig.CacheConfig cacheConfig = webServicesJmsConfig.jms().connectionCache();
    int cacheSize = cacheConfig.getMaxSize();
    connectionCache = CacheBuilder.newBuilder().maximumSize(cacheSize)
            .concurrencyLevel(cacheConfig.getConcurrencyLevel()).initialCapacity(cacheConfig.getInitialSize())
            .build(new CacheLoader<SoapJmsUri, Connection>() {
                private AtomicInteger atomicInteger = new AtomicInteger(0);

                @Override//from   ww w  .  j  a v  a 2  s  .  c om
                public Connection load(SoapJmsUri soapJmsUri) throws NamingException, JMSException {
                    String lookupVariant = soapJmsUri.getLookupVariant();
                    JmsFactory jmsFactory = jmsPlugin.getJmsFactory();
                    Connection connection;

                    if (SoapJmsUri.JNDI_LOOKUP_VARIANT.equals(lookupVariant)) {
                        String jndiConnectionFactoryName = soapJmsUri.getParameter("jndiConnectionFactoryName");
                        if (StringUtils.isBlank(jndiConnectionFactoryName)) {
                            throw new IllegalArgumentException(
                                    "Missing jndiConnectionFactoryName parameter for JMS URI "
                                            + soapJmsUri.toString());
                        }

                        String connectionName = soapJmsUri.getConnectionName();
                        if (connectionName == null) {
                            connectionName = String.format(ANONYMOUS_CONNECTION_PATTERN,
                                    atomicInteger.getAndIncrement());
                        }

                        ConnectionDefinition connectionDefinition = jmsFactory.createConnectionDefinition(
                                connectionName,
                                soapJmsUri.getConfiguration(webServicesJmsConfig).jms().getConnection(),
                                (ConnectionFactory) SoapJmsUri.getContext(soapJmsUri)
                                        .lookup(jndiConnectionFactoryName));

                        connection = jmsFactory.createConnection(connectionDefinition);
                        jmsPlugin.registerConnection(connection, connectionDefinition);
                    } else if (SoapJmsUri.SEED_QUEUE_LOOKUP_VARIANT.equals(lookupVariant)
                            || SoapJmsUri.SEED_TOPIC_LOOKUP_VARIANT.equals(lookupVariant)) {
                        String connectionName = soapJmsUri.getConnectionName();

                        if (StringUtils.isBlank(connectionName)) {
                            throw new IllegalArgumentException(
                                    "Missing connectionName parameter for JMS URI " + soapJmsUri.toString());
                        }

                        connection = jmsPlugin.getConnection(connectionName);
                    } else {
                        throw new IllegalArgumentException("Unsupported lookup variant " + lookupVariant
                                + " for JMS URI " + soapJmsUri.toString());
                    }

                    if (connection == null) {
                        throw new PluginException(
                                "Unable to resolve connection for JMS URI " + soapJmsUri.toString());
                    }

                    return connection;
                }
            });

    for (Map.Entry<String, EndpointDefinition> endpointEntry : wsPlugin
            .getEndpointDefinitions(SUPPORTED_BINDINGS).entrySet()) {
        EndpointDefinition endpointDefinition = endpointEntry.getValue();
        String endpointName = endpointEntry.getKey();
        String serviceName = endpointDefinition.getServiceName().getLocalPart();
        String portName = endpointDefinition.getPortName().getLocalPart();
        String serviceNameAndServicePort = serviceName + "-" + portName;

        SoapJmsUri uri;
        try {
            uri = SoapJmsUri.parse(new URI(endpointDefinition.getUrl()));
            uri.setEndpointName(endpointName);
        } catch (URISyntaxException e) {
            throw new PluginException("Unable to parse endpoint URI", e);
        }

        WebServicesJmsConfig.JmsEndpointConfig endpointConfiguration = uri
                .getConfiguration(webServicesJmsConfig);
        Connection connection;
        try {
            connection = connectionCache.get(uri);
        } catch (Exception e) {
            throw new PluginException("Unable to create JMS connection for WS " + serviceNameAndServicePort, e);
        }

        Session session;
        try {
            session = connection.createSession(endpointConfiguration.jms().isTransactional(),
                    Session.AUTO_ACKNOWLEDGE);
        } catch (JMSException e) {
            throw new PluginException("Unable to create JMS session for WS " + serviceNameAndServicePort, e);
        }

        Destination destination;
        try {
            destination = SoapJmsUri.getDestination(uri, session);
        } catch (Exception e) {
            throw new PluginException("Unable to create JMS destination for WS " + serviceNameAndServicePort,
                    e);
        }

        WSJmsMessageListener messageListener = new WSJmsMessageListener(uri,
                new JmsAdapter(wsPlugin.createWSEndpoint(endpointDefinition, null)), session);

        String messageListenerName = String.format(LISTENER_NAME_PATTERN, endpointName);
        try {
            jmsPlugin.registerMessageListener(new MessageListenerInstanceDefinition(messageListenerName,
                    uri.getConnectionName(), session, destination, endpointConfiguration.jms().getSelector(),
                    messageListener, endpointConfiguration.jms().getMessagePoller()));
        } catch (Exception e) {
            throw SeedException.wrap(e, WSJmsErrorCodes.UNABLE_TO_REGISTER_MESSAGE_LISTENER)
                    .put("messageListenerName", messageListenerName);
        }
        wsJmsMessageListeners.add(messageListener);
    }

    return InitState.INITIALIZED;
}

From source file:com.npower.dm.multiplexor.Multiplexor.java

public void init(ActionServlet arg0, ModuleConfig arg1) throws ServletException {
    log.info("Starting SMS Multiplexor Daemon ...");
    connection = null;/*from  w ww  .ja  v a 2s.  co m*/
    session = null;
    try {
        // Load Mapping Table
        this.mappingTable = this.loadMappingTable(this.getMappingFile());

        // Initialize and connect to JMS Queue
        JndiContextFactory jndiFactory = JndiContextFactory.newInstance(new Properties());
        Context jndiCtx = jndiFactory.getJndiContext();
        JMSManager jmsManager = JMSManager.newInstance(jndiCtx);

        QueueConnectionFactory connectionFactory = jmsManager.getQueueConnectionFactory();
        connection = connectionFactory.createQueueConnection();
        session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        // Create or get outgoing queue
        Queue queue = jmsManager.getQueue(this.getIncomingQueueName(), null);
        QueueReceiver receiver = session.createReceiver(queue);
        receiver.setMessageListener(this);

        // Start JMS Listener
        connection.start();

        log.info("SMS Multiplexor Daemon has been started.");
    } catch (Exception e) {
        log.error("failure to initialize " + this.getClass().getCanonicalName(), e);
    } finally {
    }
}

From source file:com.amazon.sqs.javamessaging.SQSConnection.java

/**
 * Creates a <code>Session</code>
 * /*from   w  ww  .  ja  v  a 2  s .  c  o  m*/
 * @param transacted
 *            Only false is supported.
 * @param acknowledgeMode
 *            Legal values are <code>Session.AUTO_ACKNOWLEDGE</code>,
 *            <code>Session.CLIENT_ACKNOWLEDGE</code>,
 *            <code>Session.DUPS_OK_ACKNOWLEDGE</code>, and
 *            <code>SQSSession.UNORDERED_ACKNOWLEDGE</code>
 * @return a new session.
 * @throws JMSException
 *             If the QueueConnection object fails to create a session due
 *             to some internal error or lack of support for the specific
 *             transaction and acknowledge mode.
 */
@Override
public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException {
    checkClosed();
    actionOnConnectionTaken = true;
    if (transacted || acknowledgeMode == Session.SESSION_TRANSACTED)
        throw new JMSException("SQSSession does not support transacted");

    SQSSession sqsSession;
    if (acknowledgeMode == Session.AUTO_ACKNOWLEDGE) {
        sqsSession = new SQSSession(this,
                AcknowledgeMode.ACK_AUTO.withOriginalAcknowledgeMode(acknowledgeMode));
    } else if (acknowledgeMode == Session.CLIENT_ACKNOWLEDGE
            || acknowledgeMode == Session.DUPS_OK_ACKNOWLEDGE) {
        sqsSession = new SQSSession(this,
                AcknowledgeMode.ACK_RANGE.withOriginalAcknowledgeMode(acknowledgeMode));
    } else if (acknowledgeMode == SQSSession.UNORDERED_ACKNOWLEDGE) {
        sqsSession = new SQSSession(this,
                AcknowledgeMode.ACK_UNORDERED.withOriginalAcknowledgeMode(acknowledgeMode));
    } else {
        LOG.error("Unrecognized acknowledgeMode. Cannot create Session.");
        throw new JMSException("Unrecognized acknowledgeMode. Cannot create Session.");
    }
    synchronized (stateLock) {
        checkClosing();
        sessions.add(sqsSession);

        /**
         * Any new sessions created on a started connection should be
         * started on creation
         */
        if (running) {
            sqsSession.start();
        }
    }

    return sqsSession;
}

From source file:org.springframework.jms.connection.ConnectionFactoryUtils.java

/**
 * Obtain a JMS QueueSession that is synchronized with the current transaction, if any.
 * <p>Mainly intended for use with the JMS 1.0.2 API.
 * @param cf the ConnectionFactory to obtain a Session for
 * @param existingCon the existing JMS Connection to obtain a Session for
 * (may be {@code null})/*  w  ww.  ja va  2  s.  c om*/
 * @param synchedLocalTransactionAllowed whether to allow for a local JMS transaction
 * that is synchronized with a Spring-managed transaction (where the main transaction
 * might be a JDBC-based one for a specific DataSource, for example), with the JMS
 * transaction committing right after the main transaction. If not allowed, the given
 * ConnectionFactory needs to handle transaction enlistment underneath the covers.
 * @return the transactional Session, or {@code null} if none found
 * @throws JMSException in case of JMS failure
 */
@Nullable
public static QueueSession getTransactionalQueueSession(final QueueConnectionFactory cf,
        @Nullable final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed)
        throws JMSException {

    return (QueueSession) doGetTransactionalSession(cf, new ResourceFactory() {
        @Override
        @Nullable
        public Session getSession(JmsResourceHolder holder) {
            return holder.getSession(QueueSession.class, existingCon);
        }

        @Override
        @Nullable
        public Connection getConnection(JmsResourceHolder holder) {
            return (existingCon != null ? existingCon : holder.getConnection(QueueConnection.class));
        }

        @Override
        public Connection createConnection() throws JMSException {
            return cf.createQueueConnection();
        }

        @Override
        public Session createSession(Connection con) throws JMSException {
            return ((QueueConnection) con).createQueueSession(synchedLocalTransactionAllowed,
                    Session.AUTO_ACKNOWLEDGE);
        }

        @Override
        public boolean isSynchedLocalTransactionAllowed() {
            return synchedLocalTransactionAllowed;
        }
    }, true);
}

From source file:com.legstar.mq.client.AbstractCicsMQ.java

/**
 * Create a new JMS session./*from   w  ww .  ja va 2 s  . co m*/
 * <p/>
 * There is no support for transactions.
 * 
 * @return new JMS session
 * @throws CicsMQConnectionException if session cannot be created
 */
protected QueueSession createQueueSession() throws CicsMQConnectionException {
    try {
        boolean transacted = false;
        QueueSession session = getJmsConnection().createQueueSession(transacted, Session.AUTO_ACKNOWLEDGE);
        return session;
    } catch (JMSException e) {
        throw new CicsMQConnectionException(e);
    }
}

From source file:org.dawnsci.commandserver.core.producer.ProcessConsumer.java

/**
 * Parse the queue for stale jobs and things that should be rerun.
 * @param bean/*from  w w  w .jav  a 2  s.  c  o m*/
 * @throws Exception 
 */
private void processStatusQueue(URI uri, String statusQName) throws Exception {

    QueueConnection qCon = null;

    try {
        QueueConnectionFactory connectionFactory = ConnectionFactoryFacade.createConnectionFactory(uri);
        qCon = connectionFactory.createQueueConnection();
        QueueSession qSes = qCon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = qSes.createQueue(statusQName);
        qCon.start();

        QueueBrowser qb = qSes.createBrowser(queue);

        @SuppressWarnings("rawtypes")
        Enumeration e = qb.getEnumeration();

        ObjectMapper mapper = new ObjectMapper();

        Map<String, StatusBean> failIds = new LinkedHashMap<String, StatusBean>(7);
        List<String> removeIds = new ArrayList<String>(7);
        while (e.hasMoreElements()) {
            Message m = (Message) e.nextElement();
            if (m == null)
                continue;
            if (m instanceof TextMessage) {
                TextMessage t = (TextMessage) m;

                try {
                    @SuppressWarnings("unchecked")
                    final StatusBean qbean = mapper.readValue(t.getText(), getBeanClass());
                    if (qbean == null)
                        continue;
                    if (qbean.getStatus() == null)
                        continue;
                    if (!qbean.getStatus().isStarted()) {
                        failIds.put(t.getJMSMessageID(), qbean);
                        continue;
                    }

                    // If it has failed, we clear it up
                    if (qbean.getStatus() == Status.FAILED) {
                        removeIds.add(t.getJMSMessageID());
                        continue;
                    }
                    if (qbean.getStatus() == Status.NONE) {
                        removeIds.add(t.getJMSMessageID());
                        continue;
                    }

                    // If it is running and older than a certain time, we clear it up
                    if (qbean.getStatus() == Status.RUNNING) {
                        final long submitted = qbean.getSubmissionTime();
                        final long current = System.currentTimeMillis();
                        if (current - submitted > getMaximumRunningAge()) {
                            removeIds.add(t.getJMSMessageID());
                            continue;
                        }
                    }

                    if (qbean.getStatus().isFinal()) {
                        final long submitted = qbean.getSubmissionTime();
                        final long current = System.currentTimeMillis();
                        if (current - submitted > getMaximumCompleteAge()) {
                            removeIds.add(t.getJMSMessageID());
                        }
                    }

                } catch (Exception ne) {
                    System.out.println("Message " + t.getText() + " is not legal and will be removed.");
                    removeIds.add(t.getJMSMessageID());
                }
            }
        }

        // We fail the non-started jobs now - otherwise we could
        // actually start them late. TODO check this
        final List<String> ids = new ArrayList<String>();
        ids.addAll(failIds.keySet());
        ids.addAll(removeIds);

        if (ids.size() > 0) {

            for (String jMSMessageID : ids) {
                MessageConsumer consumer = qSes.createConsumer(queue, "JMSMessageID = '" + jMSMessageID + "'");
                Message m = consumer.receive(1000);
                if (removeIds.contains(jMSMessageID))
                    continue; // We are done

                if (m != null && m instanceof TextMessage) {
                    MessageProducer producer = qSes.createProducer(queue);
                    final StatusBean bean = failIds.get(jMSMessageID);
                    bean.setStatus(Status.FAILED);
                    producer.send(qSes.createTextMessage(mapper.writeValueAsString(bean)));

                    System.out.println("Failed job " + bean.getName() + " messageid(" + jMSMessageID + ")");

                }
            }
        }
    } finally {
        if (qCon != null)
            qCon.close();
    }

}

From source file:org.wso2.carbon.andes.event.core.internal.delivery.jms.JMSDeliveryManager.java

/**
 * {@inheritDoc}/*from w  w w. j a va 2  s.  c o  m*/
 */
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);
    }
}