org.panksdmz.jms.tibco.MessageSenderBean.java Source code

Java tutorial

Introduction

Here is the source code for org.panksdmz.jms.tibco.MessageSenderBean.java

Source

package org.panksdmz.jms.tibco;

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;

import org.springframework.jms.connection.CachingConnectionFactory;

import com.siemens.soarian.se.dates.CaliHDateTime;

/*
 * Copyright(c) 2013 Siemens Medical Solutions Health
 * Services Corporation.  All rights reserved.  This software is
 * confidential, proprietary to Siemens, is protected by
 * copyright laws in the U.S. and abroad, and is licensed for use
 * by customers only in strict accordance with the license
 * agreement governing its use.
 */

public class MessageSenderBean {

    private CachingConnectionFactory connectionFactory;
    private String sendQueueName;

    public CachingConnectionFactory getConnectionFactory() {
        return connectionFactory;
    }

    public void setConnectionFactory(CachingConnectionFactory connectionFactory) {
        this.connectionFactory = connectionFactory;
    }

    public String getSendQueueName() {
        return sendQueueName;
    }

    public void setSendQueueName(String sendQueueName) {
        this.sendQueueName = sendQueueName;
    }

    public void send() {
        try {
            QueueConnection connection = connectionFactory.createQueueConnection();
            QueueSession session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
            Queue queue = session.createQueue(sendQueueName);
            QueueSender sender = session.createSender(queue);
            TextMessage message = session
                    .createTextMessage("Message @ " + CaliHDateTime.now().getTimeInMillis() + " from thread "
                            + Thread.currentThread().getId() + " from session [" + session.toString() + "]");

            sender.send(message);
            session.close();

        } catch (JMSException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}