Search in sources :

Example 1 with Session

use of javax.jms.Session in project hive by apache.

the class TestMsgBusConnection method connectClient.

private void connectClient() throws JMSException {
    ConnectionFactory connFac = new ActiveMQConnectionFactory("tcp://localhost:61616");
    Connection conn = connFac.createConnection();
    conn.start();
    Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
    Destination hcatTopic = session.createTopic("planetlab.hcat");
    consumer = session.createConsumer(hcatTopic);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) Connection(javax.jms.Connection) Session(javax.jms.Session)

Example 2 with Session

use of javax.jms.Session in project opennms by OpenNMS.

the class JmsNorthbounder method forwardAlarms.

/* (non-Javadoc)
     * @see org.opennms.netmgt.alarmd.api.support.AbstractNorthbounder#forwardAlarms(java.util.List)
     */
@Override
public void forwardAlarms(List<NorthboundAlarm> alarms) throws NorthbounderException {
    for (final NorthboundAlarm alarm : alarms) {
        final Integer count = alarm.getCount();
        LOG.debug("Does destination {} take only first occurances? {} Is new alarm? Has count of {}.", m_jmsDestination.getName(), m_jmsDestination.isFirstOccurrenceOnly(), count);
        if (count > 1 && m_jmsDestination.isFirstOccurrenceOnly()) {
            LOG.debug("Skipping because not new alarm.");
            continue;
        }
        LOG.debug("Attempting to send a message to {} of type {}", m_jmsDestination.getJmsDestination(), m_jmsDestination.getDestinationType());
        try {
            m_template.send(m_jmsDestination.getJmsDestination(), new MessageCreator() {

                @Override
                public Message createMessage(Session session) throws JMSException {
                    if (m_jmsDestination.isSendAsObjectMessageEnabled()) {
                        return session.createObjectMessage(alarm);
                    } else {
                        return session.createTextMessage(convertAlarmToText(alarm));
                    }
                }
            });
            LOG.debug("Sent message");
        } catch (JmsException e) {
            LOG.error("Unable to send alarm to northbound JMS because {}", e.getLocalizedMessage(), e);
        }
    }
}
Also used : Message(javax.jms.Message) JmsException(org.springframework.jms.JmsException) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 3 with Session

use of javax.jms.Session in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850LogItemRequestMessageSender method send.

public void send(final Iec61850LogItemRequestMessage iec61850LogItemRequestMessage) {
    LOGGER.debug("Sending Iec61850LogItemRequestMessage");
    this.iec61850LogItemRequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage();
            objectMessage.setJMSType(Constants.IEC61850_LOG_ITEM_REQUEST);
            objectMessage.setStringProperty(Constants.IS_INCOMING, iec61850LogItemRequestMessage.isIncoming().toString());
            objectMessage.setStringProperty(Constants.ENCODED_MESSAGE, iec61850LogItemRequestMessage.getEncodedMessage());
            objectMessage.setStringProperty(Constants.DECODED_MESSAGE, iec61850LogItemRequestMessage.getDecodedMessage());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, iec61850LogItemRequestMessage.getDeviceIdentification());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, iec61850LogItemRequestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.IS_VALID, iec61850LogItemRequestMessage.isValid().toString());
            objectMessage.setIntProperty(Constants.PAYLOAD_MESSAGE_SERIALIZED_SIZE, iec61850LogItemRequestMessage.getPayloadMessageSerializedSize());
            return objectMessage;
        }
    });
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 4 with Session

use of javax.jms.Session in project Protocol-Adapter-IEC61850 by OSGP.

the class OsgpRequestMessageSender method send.

public void send(final RequestMessage requestMessage, final String messageType) {
    LOGGER.info("Sending request message to OSGP.");
    this.iec61850RequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(requestMessage);
            objectMessage.setJMSType(messageType);
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, requestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, requestMessage.getDeviceIdentification());
            return objectMessage;
        }
    });
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) RequestMessage(com.alliander.osgp.shared.infra.jms.RequestMessage) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 5 with Session

use of javax.jms.Session in project javaee7-samples by javaee-samples.

the class ClassicMessageReceiver method receiveMessage.

public String receiveMessage() {
    String response = null;
    Connection connection = null;
    try {
        connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer messageConsumer = session.createConsumer(demoQueue);
        Message message = messageConsumer.receive(5000);
        response = message.getBody(String.class);
    } catch (JMSException ex) {
        ex.printStackTrace();
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException ex) {
                ex.printStackTrace();
            }
        }
    }
    return response;
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Aggregations

Session (javax.jms.Session)2127 Connection (javax.jms.Connection)1373 MessageConsumer (javax.jms.MessageConsumer)1309 MessageProducer (javax.jms.MessageProducer)1304 Test (org.junit.Test)1156 TextMessage (javax.jms.TextMessage)1054 Message (javax.jms.Message)845 Queue (javax.jms.Queue)538 JMSException (javax.jms.JMSException)375 Destination (javax.jms.Destination)280 ConnectionFactory (javax.jms.ConnectionFactory)206 TopicSession (javax.jms.TopicSession)205 Topic (javax.jms.Topic)177 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)164 BytesMessage (javax.jms.BytesMessage)160 TopicConnection (javax.jms.TopicConnection)152 CountDownLatch (java.util.concurrent.CountDownLatch)128 ObjectMessage (javax.jms.ObjectMessage)120 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)116 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)110