Search in sources :

Example 86 with ObjectMessage

use of javax.jms.ObjectMessage in project openolat by klemens.

the class CertificatesManagerImpl method onMessage.

@Override
public void onMessage(Message message) {
    if (message instanceof ObjectMessage) {
        try {
            ObjectMessage objMsg = (ObjectMessage) message;
            JmsCertificateWork workUnit = (JmsCertificateWork) objMsg.getObject();
            doCertificate(workUnit);
            message.acknowledge();
        } catch (JMSException e) {
            log.error("", e);
        } finally {
            dbInstance.commitAndCloseSession();
        }
    }
}
Also used : JmsCertificateWork(org.olat.course.certificate.model.JmsCertificateWork) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException)

Example 87 with ObjectMessage

use of javax.jms.ObjectMessage in project tech by ffyyhh995511.

the class RequestSubmit method submit.

public void submit(HashMap<Serializable, Serializable> requestParam) throws Exception {
    ObjectMessage message = session.createObjectMessage(requestParam);
    producer.send(message);
    session.commit();
}
Also used : ObjectMessage(javax.jms.ObjectMessage)

Example 88 with ObjectMessage

use of javax.jms.ObjectMessage in project cayenne by apache.

the class JMSBridge method sendExternalEvent.

@Override
protected void sendExternalEvent(CayenneEvent localEvent) throws Exception {
    ObjectMessage message = sendSession.createObjectMessage(eventToMessageObject(localEvent));
    message.setObjectProperty(JMSBridge.VM_ID_PROPERTY, JMSBridge.VM_ID);
    publisher.publish(message);
}
Also used : ObjectMessage(javax.jms.ObjectMessage)

Example 89 with ObjectMessage

use of javax.jms.ObjectMessage in project vcell by virtualcell.

the class VCMessageJms method show.

public String show() {
    StringBuffer buffer = new StringBuffer();
    try {
        java.util.Enumeration enum1 = jmsMessage.getPropertyNames();
        while (enum1.hasMoreElements()) {
            String propName = (String) enum1.nextElement();
            try {
                String value = jmsMessage.getStringProperty(propName);
                buffer.append(" " + propName + "='" + value + "'");
            } catch (MessagePropertyNotFoundException ex) {
                // definitely should not happen
                delegate.onException(ex);
            }
        }
        int maxContentLength = 120;
        if (jmsMessage instanceof TextMessage) {
            buffer.append("  textContent='");
            String textContent = ((TextMessage) jmsMessage).getText();
            if (textContent != null && textContent.length() > maxContentLength) {
                buffer.append(textContent.substring(0, maxContentLength - 3) + "...");
            } else {
                buffer.append(textContent);
            }
            buffer.append("'");
        } else if (jmsMessage instanceof ObjectMessage) {
            buffer.append("  objectContent='");
            String text = "" + ((ObjectMessage) jmsMessage).getObject();
            if (text.length() > maxContentLength) {
                buffer.append(text.substring(0, maxContentLength - 3) + "...");
            } else {
                buffer.append(text);
            }
            buffer.append("'");
        }
    } catch (JMSException e) {
        e.printStackTrace(System.out);
        throw new RuntimeException(e.getMessage(), e);
    }
    return buffer.toString();
}
Also used : MessagePropertyNotFoundException(cbit.vcell.message.MessagePropertyNotFoundException) Enumeration(java.util.Enumeration) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage)

Example 90 with ObjectMessage

use of javax.jms.ObjectMessage in project rocketmq-externals by apache.

the class BaseJmsSourceTask method getMessageContent.

@SuppressWarnings("unchecked")
public ByteBuffer getMessageContent(Message message) throws JMSException {
    byte[] data = null;
    if (message instanceof TextMessage) {
        data = ((TextMessage) message).getText().getBytes();
    } else if (message instanceof ObjectMessage) {
        data = JSON.toJSONBytes(((ObjectMessage) message).getObject());
    } else if (message instanceof BytesMessage) {
        BytesMessage bytesMessage = (BytesMessage) message;
        data = new byte[(int) bytesMessage.getBodyLength()];
        bytesMessage.readBytes(data);
    } else if (message instanceof MapMessage) {
        MapMessage mapMessage = (MapMessage) message;
        Map<String, Object> map = new HashMap<>();
        Enumeration<Object> names = mapMessage.getMapNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement().toString();
            map.put(name, mapMessage.getObject(name));
        }
        data = JSON.toJSONBytes(map);
    } else if (message instanceof StreamMessage) {
        StreamMessage streamMessage = (StreamMessage) message;
        ByteArrayOutputStream bis = new ByteArrayOutputStream();
        byte[] by = new byte[1024];
        int i = 0;
        while ((i = streamMessage.readBytes(by)) != -1) {
            bis.write(by, 0, i);
        }
        data = bis.toByteArray();
    } else {
        // The exception is printed and does not need to be written as a DataConnectException
        throw new RuntimeException("message type exception");
    }
    return ByteBuffer.wrap(data);
}
Also used : Enumeration(java.util.Enumeration) MapMessage(javax.jms.MapMessage) BytesMessage(javax.jms.BytesMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMessage(javax.jms.ObjectMessage) StreamMessage(javax.jms.StreamMessage) HashMap(java.util.HashMap) Map(java.util.Map) TextMessage(javax.jms.TextMessage)

Aggregations

ObjectMessage (javax.jms.ObjectMessage)227 Test (org.junit.Test)85 JMSException (javax.jms.JMSException)82 Session (javax.jms.Session)79 Message (javax.jms.Message)70 MessageProducer (javax.jms.MessageProducer)64 MessageConsumer (javax.jms.MessageConsumer)52 Connection (javax.jms.Connection)46 Queue (javax.jms.Queue)40 TextMessage (javax.jms.TextMessage)38 BytesMessage (javax.jms.BytesMessage)30 Destination (javax.jms.Destination)29 MapMessage (javax.jms.MapMessage)28 AbstractServiceComponentAgentFunctionalIntegrationTest (com.hack23.cia.service.component.agent.impl.AbstractServiceComponentAgentFunctionalIntegrationTest)25 StreamMessage (javax.jms.StreamMessage)21 HashMap (java.util.HashMap)18 Serializable (java.io.Serializable)17 Map (java.util.Map)16 ArrayList (java.util.ArrayList)13 QueueSession (javax.jms.QueueSession)11