Search in sources :

Example 31 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project brave by openzipkin.

the class TracingMessageListenerTest method starts_new_trace_if_none_exists_noConsumer.

@Test
public void starts_new_trace_if_none_exists_noConsumer() {
    tracingMessageListener = new TracingMessageListener(delegate, jmsTracing, false);
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    onMessageConsumed(message);
    testSpanHandler.takeLocalSpan();
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

Example 32 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project brave by openzipkin.

the class TracingMessageListenerTest method reports_span_if_consume_fails.

@Test
public void reports_span_if_consume_fails() {
    tracingMessageListener = new TracingMessageListener(delegate, jmsTracing, false);
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    RuntimeException error = new RuntimeException("Test exception");
    onMessageConsumeFailed(message, error);
    assertThat(testSpanHandler.takeLocalSpan().error()).isEqualTo(error);
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

Example 33 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project vcell by virtualcell.

the class ClientTopicMessageCollector method onTopicMessage.

/**
 * Insert the method's description here.
 * Creation date: (10/23/2001 3:58:52 PM)
 * @param message javax.jms.Message
 * @throws VCMessagingException
 */
public void onTopicMessage(VCMessage message, VCMessageSession session) {
    if (message == null) {
        return;
    }
    try {
        // Check if it's a broadcast message
        if (message instanceof VCMessageJms) {
            VCMessageJms vcMessageJms = (VCMessageJms) message;
            javax.jms.Message myMessage = vcMessageJms.getJmsMessage();
            if (myMessage instanceof ActiveMQTextMessage) {
                ActiveMQTextMessage myAMQ = (ActiveMQTextMessage) myMessage;
                if (myAMQ.getType().equalsIgnoreCase(MessageConstants.MESSAGE_TYPE_BROADCASTMESSAGE_VALUE)) {
                    fireMessageEvent(new VCellMessageEvent(this, System.currentTimeMillis() + "", new MessageData(myAMQ.getText()), VCellMessageEvent.VCELL_MESSAGEEVENT_TYPE_BROADCAST, null));
                    return;
                }
            }
        }
        if (message.getObjectContent() == null) {
            throw new Exception(this.getClass().getName() + ".onTopicMessage: unimplemented message class " + message.show());
        }
        setTimeSinceLastMessage(System.currentTimeMillis());
        String msgType = message.getStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
        if (msgType == null) {
            throw new Exception(this.getClass().getName() + ".onTopicMessage: message type NULL for message " + message);
        }
        if (msgType.equals(MessageConstants.MESSAGE_TYPE_SIMSTATUS_VALUE)) {
            String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
            StatusMessage statusMessage = new StatusMessage(message);
            String userName = VCMessagingConstants.USERNAME_PROPERTY_VALUE_ALL;
            if (message.propertyExists(VCMessagingConstants.USERNAME_PROPERTY)) {
                userName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
            }
            SimulationJobStatus newJobStatus = statusMessage.getJobStatus();
            if (newJobStatus == null) {
                return;
            }
            VCSimulationIdentifier vcSimID = newJobStatus.getVCSimulationIdentifier();
            Double progress = statusMessage.getProgress();
            Double timePoint = statusMessage.getTimePoint();
            fireSimulationJobStatusEvent(new SimulationJobStatusEvent(this, vcSimID.getID(), newJobStatus, progress, timePoint, messageUserName));
        } else if (msgType.equals(MessageConstants.MESSAGE_TYPE_EXPORT_EVENT_VALUE)) {
            String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
            ExportEvent event = (ExportEvent) message.getObjectContent();
            fireExportEvent(event);
        } else if (msgType.equals(MessageConstants.MESSAGE_TYPE_DATA_EVENT_VALUE)) {
            String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
            DataJobEvent event = (DataJobEvent) message.getObjectContent();
            fireMessageEvent(event);
        } else if (msgType.equals(MessageConstants.MESSAGE_TYPE_BROADCASTMESSAGE_VALUE)) {
            String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
            fireMessageEvent(new VCellMessageEvent(this, System.currentTimeMillis() + "", new MessageData((BigString) message.getObjectContent()), VCellMessageEvent.VCELL_MESSAGEEVENT_TYPE_BROADCAST, messageUserName));
        } else {
            throw new Exception(this.getClass().getName() + ".onControlTopicMessage: Unimplemented message " + message.show());
        }
    } catch (Exception e) {
        e.printStackTrace();
        lg.error(e.getMessage(), e);
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) VCMessageJms(cbit.vcell.message.jms.VCMessageJms) MessageData(cbit.rmi.event.MessageData) ExportEvent(cbit.rmi.event.ExportEvent) BigString(org.vcell.util.BigString) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) BigString(org.vcell.util.BigString) VCMessagingException(cbit.vcell.message.VCMessagingException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) StatusMessage(cbit.vcell.message.messages.StatusMessage) DataJobEvent(cbit.rmi.event.DataJobEvent) VCellMessageEvent(cbit.rmi.event.VCellMessageEvent) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus)

Example 34 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project nifi by apache.

the class TestJmsConsumer method testMap2FlowFileTextMessage.

@Test
public void testMap2FlowFileTextMessage() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(GetJMSQueue.class);
    TextMessage textMessage = new ActiveMQTextMessage();
    String payload = "Hello world!";
    textMessage.setText(payload);
    ProcessContext context = runner.getProcessContext();
    ProcessSession session = runner.getProcessSessionFactory().createSession();
    ProcessorInitializationContext pic = new MockProcessorInitializationContext(runner.getProcessor(), (MockProcessContext) runner.getProcessContext());
    JmsProcessingSummary summary = JmsConsumer.map2FlowFile(context, session, textMessage, true, pic.getLogger());
    assertEquals("TextMessage content length should equal to FlowFile content size", payload.length(), summary.getLastFlowFile().getSize());
    final byte[] buffer = new byte[payload.length()];
    runner.clearTransferState();
    session.read(summary.getLastFlowFile(), new InputStreamCallback() {

        @Override
        public void process(InputStream in) throws IOException {
            StreamUtils.fillBuffer(in, buffer, false);
        }
    });
    String contentString = new String(buffer, "UTF-8");
    assertEquals("", payload, contentString);
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) TestRunner(org.apache.nifi.util.TestRunner) InputStream(java.io.InputStream) MockProcessorInitializationContext(org.apache.nifi.util.MockProcessorInitializationContext) JmsProcessingSummary(org.apache.nifi.processors.standard.util.JmsProcessingSummary) IOException(java.io.IOException) ProcessContext(org.apache.nifi.processor.ProcessContext) MockProcessContext(org.apache.nifi.util.MockProcessContext) MockProcessorInitializationContext(org.apache.nifi.util.MockProcessorInitializationContext) ProcessorInitializationContext(org.apache.nifi.processor.ProcessorInitializationContext) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) InputStreamCallback(org.apache.nifi.processor.io.InputStreamCallback) TextMessage(javax.jms.TextMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

Example 35 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.

the class ActiveMQXAConnectionFactoryTest method testConsumerCloseTransactionalSendReceive.

public void testConsumerCloseTransactionalSendReceive() throws Exception {
    ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
    XAConnection connection1 = (XAConnection) cf1.createConnection();
    connection1.start();
    XASession session = connection1.createXASession();
    XAResource resource = session.getXAResource();
    Destination dest = new ActiveMQQueue(getName());
    // publish a message
    Xid tid = createXid();
    resource.start(tid, XAResource.TMNOFLAGS);
    MessageProducer producer = session.createProducer(dest);
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    message.setText(getName());
    producer.send(message);
    producer.close();
    resource.end(tid, XAResource.TMSUCCESS);
    resource.commit(tid, true);
    session.close();
    session = connection1.createXASession();
    MessageConsumer consumer = session.createConsumer(dest);
    tid = createXid();
    resource = session.getXAResource();
    resource.start(tid, XAResource.TMNOFLAGS);
    TextMessage receivedMessage = (TextMessage) consumer.receive(1000);
    consumer.close();
    assertNotNull(receivedMessage);
    assertEquals(getName(), receivedMessage.getText());
    resource.end(tid, XAResource.TMSUCCESS);
    resource.commit(tid, true);
    session = connection1.createXASession();
    consumer = session.createConsumer(dest);
    tid = createXid();
    resource = session.getXAResource();
    resource.start(tid, XAResource.TMNOFLAGS);
    assertNull(consumer.receive(1000));
    resource.end(tid, XAResource.TMSUCCESS);
    resource.commit(tid, true);
}
Also used : Destination(javax.jms.Destination) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) MessageConsumer(javax.jms.MessageConsumer) XASession(javax.jms.XASession) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) XAConnection(javax.jms.XAConnection) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Aggregations

ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)71 Test (org.junit.Test)36 TextMessage (javax.jms.TextMessage)16 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)14 Message (javax.jms.Message)10 MessageProducer (javax.jms.MessageProducer)10 MessageConsumer (javax.jms.MessageConsumer)9 MessageId (org.apache.activemq.command.MessageId)9 JMSException (javax.jms.JMSException)7 ActiveMQBytesMessage (org.apache.activemq.command.ActiveMQBytesMessage)7 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)6 MessageReference (org.apache.activemq.broker.region.MessageReference)6 Queue (org.apache.activemq.broker.region.Queue)6 ActiveMQMapMessage (org.apache.activemq.command.ActiveMQMapMessage)6 ActiveMQObjectMessage (org.apache.activemq.command.ActiveMQObjectMessage)6 ActiveMQStreamMessage (org.apache.activemq.command.ActiveMQStreamMessage)6 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)6 SystemUsage (org.apache.activemq.usage.SystemUsage)6 MutableSpan (brave.handler.MutableSpan)5 MessageNotWriteableException (javax.jms.MessageNotWriteableException)5