org.apache.activemq.command.ActiveMQMessage

Here are the examples of the java api class org.apache.activemq.command.ActiveMQMessage taken from open source projects.

1. AdvisoryTempDestinationTests#testTempMessageConsumedAdvisory()

View license
public void testTempMessageConsumedAdvisory() throws Exception {
    Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue queue = s.createTemporaryQueue();
    MessageConsumer consumer = s.createConsumer(queue);
    Topic advisoryTopic = AdvisorySupport.getMessageConsumedAdvisoryTopic((ActiveMQDestination) queue);
    MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
    //start throwing messages at the consumer
    MessageProducer producer = s.createProducer(queue);
    BytesMessage m = s.createBytesMessage();
    m.writeBytes(new byte[1024]);
    producer.send(m);
    String id = m.getJMSMessageID();
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    msg = advisoryConsumer.receive(1000);
    assertNotNull(msg);
    ActiveMQMessage message = (ActiveMQMessage) msg;
    ActiveMQMessage payload = (ActiveMQMessage) message.getDataStructure();
    String originalId = payload.getJMSMessageID();
    assertEquals(originalId, id);
}

2. AdvisoryTests#testMessageConsumedAdvisory()

Project: activemq-artemis
Source File: AdvisoryTests.java
View license
public void testMessageConsumedAdvisory() throws Exception {
    Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = s.createQueue(getClass().getName());
    MessageConsumer consumer = s.createConsumer(queue);
    Topic advisoryTopic = AdvisorySupport.getMessageConsumedAdvisoryTopic((ActiveMQDestination) queue);
    MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
    //start throwing messages at the consumer
    MessageProducer producer = s.createProducer(queue);
    BytesMessage m = s.createBytesMessage();
    m.writeBytes(new byte[1024]);
    producer.send(m);
    String id = m.getJMSMessageID();
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    msg = advisoryConsumer.receive(1000);
    assertNotNull(msg);
    ActiveMQMessage message = (ActiveMQMessage) msg;
    ActiveMQMessage payload = (ActiveMQMessage) message.getDataStructure();
    String originalId = payload.getJMSMessageID();
    assertEquals(originalId, id);
}

3. ActiveMQMessageConsumerDispatchInterceptor#createTrace()

View license
@Override
protected Trace createTrace(Object target, Object[] args) {
    if (!validate(target, args)) {
        return null;
    }
    MessageDispatch md = (MessageDispatch) args[0];
    ActiveMQMessage message = (ActiveMQMessage) md.getMessage();
    if (filterDestination(message.getDestination())) {
        return null;
    }
    // These might trigger unmarshalling.
    if (!ActiveMQClientHeader.getSampled(message, true)) {
        return traceContext.disableSampling();
    }
    String transactionId = ActiveMQClientHeader.getTraceId(message, null);
    if (transactionId != null) {
        long parentSpanId = ActiveMQClientHeader.getParentSpanId(message, SpanId.NULL);
        long spanId = ActiveMQClientHeader.getSpanId(message, SpanId.NULL);
        short flags = ActiveMQClientHeader.getFlags(message, (short) 0);
        final TraceId traceId = traceContext.createTraceId(transactionId, parentSpanId, spanId, flags);
        return traceContext.continueTraceObject(traceId);
    } else {
        return traceContext.newTraceObject();
    }
}

4. ActiveMQOriginalDestinationTest#testActiveMQOriginalDestination()

View license
@Test
public void testActiveMQOriginalDestination() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("activemq:queue:foo", "Hello World");
    assertMockEndpointsSatisfied();
    // consume from bar
    Exchange out = consumer.receive("activemq:queue:bar", 5000);
    assertNotNull(out);
    // and we should have foo as the original destination
    JmsMessage msg = out.getIn(JmsMessage.class);
    Message jms = msg.getJmsMessage();
    ActiveMQMessage amq = assertIsInstanceOf(ActiveMQMessage.class, jms);
    ActiveMQDestination original = amq.getOriginalDestination();
    assertNotNull(original);
    assertEquals("foo", original.getPhysicalName());
    assertEquals("Queue", original.getDestinationTypeAsString());
}

5. JMSUsecase1Test#testSendReceive()

View license
@Test
public void testSendReceive() throws Exception {
    // Send a message to the broker.
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, destinationType);
    System.out.println("destionation: " + destination);
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(this.deliveryMode);
    MessageConsumer consumer = session.createConsumer(destination);
    ActiveMQMessage message = new ActiveMQMessage();
    producer.send(message);
    // Make sure only 1 message was delivered.
    assertNotNull(consumer.receive(1000));
    assertNull(consumer.receiveNoWait());
}

6. PluginBrokerTest#assertMessageValid()

View license
@Override
protected void assertMessageValid(int index, Message message) throws JMSException {
    // check if broker path has been set
    assertEquals("localhost", message.getStringProperty("BrokerPath"));
    ActiveMQMessage amqMsg = (ActiveMQMessage) message;
    if (index == 7) {
        // check custom expiration
        assertTrue("expiration is in range, depends on two distinct calls to System.currentTimeMillis", 1500 < amqMsg.getExpiration() - amqMsg.getTimestamp());
    } else if (index == 9) {
        // check ceiling
        assertTrue("expiration ceeling is in range, depends on two distinct calls to System.currentTimeMillis", 59500 < amqMsg.getExpiration() - amqMsg.getTimestamp());
    } else {
        // check default expiration
        assertEquals(1000, amqMsg.getExpiration() - amqMsg.getTimestamp());
    }
    super.assertMessageValid(index, message);
}

7. JMSUsecaseTest#testSendReceive()

View license
public void testSendReceive() throws Exception {
    // Send a message to the broker.
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    destination = createDestination(session, destinationType);
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(this.deliveryMode);
    MessageConsumer consumer = session.createConsumer(destination);
    ActiveMQMessage message = new ActiveMQMessage();
    producer.send(message);
    // Make sure only 1 message was delivered.
    assertNotNull(consumer.receive(1000));
    assertNull(consumer.receiveNoWait());
}

8. OpenWireMessageConverter#createMessageDispatch()

View license
public static MessageDispatch createMessageDispatch(MessageReference reference, ServerMessage message, AMQConsumer consumer) throws IOException, JMSException {
    ActiveMQMessage amqMessage = toAMQMessage(reference, message, consumer.getMarshaller(), consumer.getOpenwireDestination());
    //we can use core message id for sequenceId
    amqMessage.getMessageId().setBrokerSequenceId(message.getMessageID());
    MessageDispatch md = new MessageDispatch();
    md.setConsumerId(consumer.getId());
    md.setRedeliveryCounter(reference.getDeliveryCount() - 1);
    md.setDeliverySequenceId(amqMessage.getMessageId().getBrokerSequenceId());
    md.setMessage(amqMessage);
    ActiveMQDestination destination = amqMessage.getDestination();
    md.setDestination(destination);
    return md;
}

9. OpenWireProtocolManager#fireAdvisory()

View license
/*
    * See AdvisoryBroker.fireAdvisory()
    */
public void fireAdvisory(AMQConnectionContext context, ActiveMQTopic topic, Command command, ConsumerId targetConsumerId) throws Exception {
    ActiveMQMessage advisoryMessage = new ActiveMQMessage();
    advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_NAME, getBrokerName());
    String id = getBrokerId() != null ? getBrokerId().getValue() : "NOT_SET";
    advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_ID, id);
    String url = context.getConnection().getLocalAddress();
    advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_URL, url);
    // set the data structure
    advisoryMessage.setDataStructure(command);
    advisoryMessage.setPersistent(false);
    advisoryMessage.setType(AdvisorySupport.ADIVSORY_MESSAGE_TYPE);
    advisoryMessage.setMessageId(new MessageId(advisoryProducerId, messageIdGenerator.getNextSequenceId()));
    advisoryMessage.setTargetConsumerId(targetConsumerId);
    advisoryMessage.setDestination(topic);
    advisoryMessage.setResponseRequired(false);
    advisoryMessage.setProducerId(advisoryProducerId);
    boolean originalFlowControl = context.isProducerFlowControl();
    final AMQProducerBrokerExchange producerExchange = new AMQProducerBrokerExchange();
    producerExchange.setConnectionContext(context);
    producerExchange.setProducerState(new ProducerState(new ProducerInfo()));
    try {
        context.setProducerFlowControl(false);
        AMQSession sess = context.getConnection().getAdvisorySession();
        if (sess != null) {
            sess.send(producerExchange.getProducerState().getInfo(), advisoryMessage, false);
        }
    } finally {
        context.setProducerFlowControl(originalFlowControl);
    }
}

10. NetworkRouteTest#before()

View license
@Before
public void before() throws Exception {
    control = EasyMock.createControl();
    localBroker = control.createMock(Transport.class);
    remoteBroker = control.createMock(Transport.class);
    NetworkBridgeConfiguration configuration = new NetworkBridgeConfiguration();
    brokerService = new BrokerService();
    BrokerInfo remoteBrokerInfo = new BrokerInfo();
    configuration.setDuplex(true);
    configuration.setNetworkTTL(5);
    brokerService.setBrokerId("broker-1");
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    brokerService.start();
    brokerService.waitUntilStarted();
    remoteBrokerInfo.setBrokerId(new BrokerId("remote-broker-id"));
    remoteBrokerInfo.setBrokerName("remote-broker-name");
    localBroker.setTransportListener(EasyMock.isA(TransportListener.class));
    ArgHolder localListenerRef = ArgHolder.holdArgsForLastVoidCall();
    remoteBroker.setTransportListener(EasyMock.isA(TransportListener.class));
    ArgHolder remoteListenerRef = ArgHolder.holdArgsForLastVoidCall();
    localBroker.start();
    remoteBroker.start();
    remoteBroker.oneway(EasyMock.isA(Object.class));
    EasyMock.expectLastCall().times(4);
    remoteBroker.oneway(EasyMock.isA(Object.class));
    ExpectationWaiter remoteInitWaiter = ExpectationWaiter.waiterForLastVoidCall();
    localBroker.oneway(remoteBrokerInfo);
    EasyMock.expect(localBroker.request(EasyMock.isA(Object.class))).andReturn(null);
    localBroker.oneway(EasyMock.isA(Object.class));
    ExpectationWaiter localInitWaiter = ExpectationWaiter.waiterForLastVoidCall();
    control.replay();
    DurableConduitBridge bridge = new DurableConduitBridge(configuration, localBroker, remoteBroker);
    bridge.setBrokerService(brokerService);
    bridge.start();
    localListener = (TransportListener) localListenerRef.getArguments()[0];
    Assert.assertNotNull(localListener);
    remoteListener = (TransportListener) remoteListenerRef.getArguments()[0];
    Assert.assertNotNull(remoteListener);
    remoteListener.onCommand(remoteBrokerInfo);
    remoteInitWaiter.assertHappens(5, TimeUnit.SECONDS);
    localInitWaiter.assertHappens(5, TimeUnit.SECONDS);
    control.verify();
    control.reset();
    ActiveMQMessage msg = new ActiveMQMessage();
    msg.setDestination(new ActiveMQTopic("test"));
    msgDispatch = new MessageDispatch();
    msgDispatch.setMessage(msg);
    ConsumerInfo path1 = new ConsumerInfo();
    path1.setDestination(msg.getDestination());
    path1.setConsumerId(new ConsumerId(new SessionId(new ConnectionId("conn-id-1"), 1), 3));
    path1.setBrokerPath(new BrokerId[] { new BrokerId("remote-broker-id"), new BrokerId("server(1)-broker-id") });
    path1Msg = new ActiveMQMessage();
    path1Msg.setDestination(AdvisorySupport.getConsumerAdvisoryTopic(path1.getDestination()));
    path1Msg.setDataStructure(path1);
    ConsumerInfo path2 = new ConsumerInfo();
    path2.setDestination(path1.getDestination());
    path2.setConsumerId(new ConsumerId(new SessionId(new ConnectionId("conn-id-2"), 2), 4));
    path2.setBrokerPath(new BrokerId[] { new BrokerId("remote-broker-id"), new BrokerId("server(2)-broker-id"), new BrokerId("server(1)-broker-id") });
    path2Msg = new ActiveMQMessage();
    path2Msg.setDestination(path1Msg.getDestination());
    path2Msg.setDataStructure(path2);
    RemoveInfo removePath1 = new RemoveInfo(path1.getConsumerId());
    RemoveInfo removePath2 = new RemoveInfo(path2.getConsumerId());
    removePath1Msg = new ActiveMQMessage();
    removePath1Msg.setDestination(path1Msg.getDestination());
    removePath1Msg.setDataStructure(removePath1);
    removePath2Msg = new ActiveMQMessage();
    removePath2Msg.setDestination(path1Msg.getDestination());
    removePath2Msg.setDataStructure(removePath2);
}

11. SelectorTest#createMessage()

Project: activemq-artemis
Source File: SelectorTest.java
View license
protected Message createMessage(String subject) throws JMSException {
    ActiveMQMessage message = new ActiveMQMessage();
    message.setJMSDestination(new ActiveMQTopic(subject));
    return message;
}

12. ForwardingBridgeTest#testForwardMessageCompressed()

View license
public void testForwardMessageCompressed() throws Exception {
    bridge.setUseCompression(true);
    // Start a producer on local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    // Start a consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
    connection2.send(consumerInfo);
    Thread.sleep(1000);
    // Give forwarding bridge a chance to finish setting up
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
    // Send the message to the local boker.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered via the remote.
    Message m = receiveMessage(connection2);
    assertNotNull(m);
    // Make sure its compressed now
    ActiveMQMessage message = (ActiveMQMessage) m;
    assertTrue(message.isCompressed());
}

13. ActiveMQMessageTest#createObject()

View license
@Override
public Object createObject() throws Exception {
    ActiveMQMessage info = new ActiveMQMessage();
    populateObject(info);
    return info;
}

14. ActiveMQMessageTest#populateObject()

View license
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ActiveMQMessage info = (ActiveMQMessage) object;
}

15. ActiveMQMessageTest#createObject()

View license
@Override
public Object createObject() throws Exception {
    ActiveMQMessage info = new ActiveMQMessage();
    populateObject(info);
    return info;
}

16. ActiveMQMessageTest#populateObject()

View license
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ActiveMQMessage info = (ActiveMQMessage) object;
}

17. UnknownHandlingSelectorTest#setUp()

View license
@Before
public void setUp() throws Exception {
    message = new ActiveMQMessage();
    message.setJMSDestination(new ActiveMQTopic("FOO.BAR"));
    message.setJMSType("selector-test");
    message.setJMSMessageID("connection:1:1:1:1");
    message.setBooleanProperty("trueProp", true);
    message.setBooleanProperty("falseProp", false);
    message.setObjectProperty("nullProp", null);
}

18. AdvisoryNetworkBridgeTest#testAddConsumerLater()

View license
public void testAddConsumerLater() throws Exception {
    createBroker1();
    createBroker2();
    Thread.sleep(1000);
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://broker1");
    Connection conn = factory.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    conn.start();
    MessageConsumer consumer = sess.createConsumer(AdvisorySupport.getNetworkBridgeAdvisoryTopic());
    ActiveMQMessage advisory = (ActiveMQMessage) consumer.receive(2000);
    assertNotNull(advisory);
    assertTrue(advisory.getDataStructure() instanceof BrokerInfo);
    assertTrue(advisory.getBooleanProperty("started"));
    assertCreatedByDuplex(advisory.getBooleanProperty("createdByDuplex"));
    broker2.stop();
    broker2.waitUntilStopped();
    advisory = (ActiveMQMessage) consumer.receive(2000);
    assertNotNull(advisory);
    assertTrue(advisory.getDataStructure() instanceof BrokerInfo);
    assertFalse(advisory.getBooleanProperty("started"));
    consumer = sess.createConsumer(AdvisorySupport.getNetworkBridgeAdvisoryTopic());
    advisory = (ActiveMQMessage) consumer.receive(1000);
    assertNull(advisory);
    conn.close();
}

19. AdvisoryNetworkBridgeTest#testAdvisory()

View license
public void testAdvisory() throws Exception {
    createBroker1();
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://broker1");
    Connection conn = factory.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    conn.start();
    MessageConsumer consumer = sess.createConsumer(AdvisorySupport.getNetworkBridgeAdvisoryTopic());
    Thread.sleep(1000);
    createBroker2();
    ActiveMQMessage advisory = (ActiveMQMessage) consumer.receive(2000);
    assertNotNull(advisory);
    assertTrue(advisory.getDataStructure() instanceof BrokerInfo);
    assertTrue(advisory.getBooleanProperty("started"));
    assertCreatedByDuplex(advisory.getBooleanProperty("createdByDuplex"));
    broker2.stop();
    broker2.waitUntilStopped();
    advisory = (ActiveMQMessage) consumer.receive(2000);
    assertNotNull(advisory);
    assertTrue(advisory.getDataStructure() instanceof BrokerInfo);
    assertFalse(advisory.getBooleanProperty("started"));
    conn.close();
}

20. AdvisoryJmxTest#testCreateDeleteDestinations()

View license
public void testCreateDeleteDestinations() throws Exception {
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
    JMXConnector connector = JMXConnectorFactory.connect(url, null);
    connector.connect();
    MBeanServerConnection connection = connector.getMBeanServerConnection();
    ObjectName name = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost");
    BrokerViewMBean brokerMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true);
    Connection conn = createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = sess.createConsumer(sess.createTopic("ActiveMQ.Advisory.Queue"));
    conn.start();
    Destination dest = sess.createQueue("test");
    brokerMbean.addQueue("test");
    ActiveMQMessage msg = (ActiveMQMessage) consumer.receive(1000);
    assertNotNull(msg);
    assertTrue(msg.getDataStructure() instanceof DestinationInfo);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getDestination(), dest);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getOperationType(), 0);
    brokerMbean.removeQueue("test");
    msg = (ActiveMQMessage) consumer.receive(1000);
    assertNotNull(msg);
    assertTrue(msg.getDataStructure() instanceof DestinationInfo);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getDestination(), dest);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getOperationType(), 1);
    brokerMbean.addQueue("test");
    msg = (ActiveMQMessage) consumer.receive(1000);
    assertNotNull(msg);
    assertTrue(msg.getDataStructure() instanceof DestinationInfo);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getDestination(), dest);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getOperationType(), 0);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getOperationType(), 0);
}

21. ActiveMQMessageConsumerDispatchInterceptor#doInBeforeTrace()

View license
@Override
protected void doInBeforeTrace(SpanRecorder recorder, Object target, Object[] args) {
    recorder.recordServiceType(ActiveMQClientConstants.ACTIVEMQ_CLIENT);
    ActiveMQSession session = ((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession();
    ActiveMQConnection connection = session.getConnection();
    Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport());
    Socket socket = ((SocketGetter) transport)._$PINPOINT$_getSocket();
    SocketAddress localSocketAddress = socket.getLocalSocketAddress();
    String endPoint = ActiveMQClientUtils.getEndPoint(localSocketAddress);
    // Endpoint should be the local socket address of the consumer.
    recorder.recordEndPoint(endPoint);
    SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress();
    String remoteAddress = ActiveMQClientUtils.getEndPoint(remoteSocketAddress);
    // Remote address is the socket address of where the consumer is connected to.
    recorder.recordRemoteAddress(remoteAddress);
    MessageDispatch md = (MessageDispatch) args[0];
    ActiveMQMessage message = (ActiveMQMessage) md.getMessage();
    ActiveMQDestination destination = message.getDestination();
    // Rpc name is the URI of the queue/topic we're consuming from.
    recorder.recordRpcName(destination.getQualifiedName());
    // Record acceptor host as the queue/topic name in order to generate virtual queue node.
    recorder.recordAcceptorHost(destination.getPhysicalName());
    String parentApplicationName = ActiveMQClientHeader.getParentApplicationName(message, null);
    if (!recorder.isRoot() && parentApplicationName != null) {
        short parentApplicationType = ActiveMQClientHeader.getParentApplicationType(message, ServiceType.UNDEFINED.getCode());
        recorder.recordParentApplication(parentApplicationName, parentApplicationType);
    }
}