Search in sources :

Example 6 with ActiveMQDestination

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

the class OpenWireMessageConverter method createMessageDispatch.

public static MessageDispatch createMessageDispatch(MessageReference reference, ICoreMessage message, WireFormat marshaller, AMQConsumer consumer) throws IOException {
    ActiveMQMessage amqMessage = toAMQMessage(reference, message, marshaller, consumer);
    // 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;
}
Also used : MessageDispatch(org.apache.activemq.command.MessageDispatch) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 7 with ActiveMQDestination

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

the class OpenWireMessageConverter method toAMQMessage.

private static ActiveMQMessage toAMQMessage(MessageReference reference, ICoreMessage coreMessage, WireFormat marshaller, AMQConsumer consumer) throws IOException {
    final ActiveMQMessage amqMsg;
    final byte coreType = coreMessage.getType();
    final Boolean compressProp = (Boolean) coreMessage.getObjectProperty(AMQ_MSG_COMPRESSED);
    final boolean isCompressed = compressProp == null ? false : compressProp.booleanValue();
    final byte[] bytes;
    final ActiveMQBuffer buffer = coreMessage.getDataBuffer();
    buffer.resetReaderIndex();
    switch(coreType) {
        case org.apache.activemq.artemis.api.core.Message.BYTES_TYPE:
            amqMsg = new ActiveMQBytesMessage();
            bytes = toAMQMessageBytesType(buffer, isCompressed);
            break;
        case org.apache.activemq.artemis.api.core.Message.MAP_TYPE:
            amqMsg = new ActiveMQMapMessage();
            bytes = toAMQMessageMapType(buffer, isCompressed);
            break;
        case org.apache.activemq.artemis.api.core.Message.OBJECT_TYPE:
            amqMsg = new ActiveMQObjectMessage();
            bytes = toAMQMessageObjectType(buffer, isCompressed);
            break;
        case org.apache.activemq.artemis.api.core.Message.STREAM_TYPE:
            amqMsg = new ActiveMQStreamMessage();
            bytes = toAMQMessageStreamType(buffer, isCompressed);
            break;
        case org.apache.activemq.artemis.api.core.Message.TEXT_TYPE:
            amqMsg = new ActiveMQTextMessage();
            bytes = toAMQMessageTextType(buffer, isCompressed);
            break;
        case org.apache.activemq.artemis.api.core.Message.DEFAULT_TYPE:
            amqMsg = new ActiveMQMessage();
            bytes = toAMQMessageDefaultType(buffer, isCompressed);
            break;
        default:
            throw new IllegalStateException("Unknown message type: " + coreMessage.getType());
    }
    final String type = coreMessage.getStringProperty(JMS_TYPE_PROPERTY);
    if (type != null) {
        amqMsg.setJMSType(type);
    }
    amqMsg.setPersistent(coreMessage.isDurable());
    amqMsg.setExpiration(coreMessage.getExpiration());
    amqMsg.setPriority(coreMessage.getPriority());
    amqMsg.setTimestamp(coreMessage.getTimestamp());
    Long brokerInTime = (Long) coreMessage.getObjectProperty(AMQ_MSG_BROKER_IN_TIME);
    if (brokerInTime == null) {
        brokerInTime = 0L;
    }
    amqMsg.setBrokerInTime(brokerInTime);
    amqMsg.setCompressed(isCompressed);
    // we need check null because messages may come from other clients
    // and those amq specific attribute may not be set.
    Long arrival = (Long) coreMessage.getObjectProperty(AMQ_MSG_ARRIVAL);
    if (arrival == null) {
        // messages from other sources (like core client) may not set this prop
        arrival = 0L;
    }
    amqMsg.setArrival(arrival);
    final String brokerPath = (String) coreMessage.getObjectProperty(AMQ_MSG_BROKER_PATH);
    if (brokerPath != null && !brokerPath.isEmpty()) {
        setAMQMsgBrokerPath(amqMsg, brokerPath);
    }
    final String clusterPath = (String) coreMessage.getObjectProperty(AMQ_MSG_CLUSTER);
    if (clusterPath != null && !clusterPath.isEmpty()) {
        setAMQMsgClusterPath(amqMsg, clusterPath);
    }
    Integer commandId = (Integer) coreMessage.getObjectProperty(AMQ_MSG_COMMAND_ID);
    if (commandId == null) {
        commandId = -1;
    }
    amqMsg.setCommandId(commandId);
    final SimpleString corrId = (SimpleString) coreMessage.getObjectProperty(JMS_CORRELATION_ID_PROPERTY);
    if (corrId != null) {
        amqMsg.setCorrelationId(corrId.toString());
    }
    final byte[] dsBytes = (byte[]) coreMessage.getObjectProperty(AMQ_MSG_DATASTRUCTURE);
    if (dsBytes != null) {
        setAMQMsgDataStructure(amqMsg, marshaller, dsBytes);
    }
    final ActiveMQDestination actualDestination = consumer.getOpenwireDestination();
    amqMsg.setDestination(OpenWireUtil.toAMQAddress(coreMessage, actualDestination));
    final Object value = coreMessage.getGroupID();
    if (value != null) {
        String groupId = value.toString();
        amqMsg.setGroupID(groupId);
    }
    Integer groupSequence = (Integer) coreMessage.getObjectProperty(AMQ_MSG_GROUP_SEQUENCE);
    if (groupSequence == null) {
        groupSequence = -1;
    }
    amqMsg.setGroupSequence(groupSequence);
    final MessageId mid;
    final byte[] midBytes = (byte[]) coreMessage.getObjectProperty(AMQ_MSG_MESSAGE_ID);
    if (midBytes != null) {
        ByteSequence midSeq = new ByteSequence(midBytes);
        mid = (MessageId) marshaller.unmarshal(midSeq);
    } else {
        mid = new MessageId(UUIDGenerator.getInstance().generateStringUUID() + ":-1");
    }
    amqMsg.setMessageId(mid);
    final byte[] origDestBytes = (byte[]) coreMessage.getObjectProperty(AMQ_MSG_ORIG_DESTINATION);
    if (origDestBytes != null) {
        setAMQMsgOriginalDestination(amqMsg, marshaller, origDestBytes);
    }
    final byte[] origTxIdBytes = (byte[]) coreMessage.getObjectProperty(AMQ_MSG_ORIG_TXID);
    if (origTxIdBytes != null) {
        setAMQMsgOriginalTransactionId(amqMsg, marshaller, origTxIdBytes);
    }
    final byte[] producerIdBytes = (byte[]) coreMessage.getObjectProperty(AMQ_MSG_PRODUCER_ID);
    if (producerIdBytes != null) {
        ProducerId producerId = (ProducerId) marshaller.unmarshal(new ByteSequence(producerIdBytes));
        amqMsg.setProducerId(producerId);
    }
    final byte[] marshalledBytes = (byte[]) coreMessage.getObjectProperty(AMQ_MSG_MARSHALL_PROP);
    if (marshalledBytes != null) {
        amqMsg.setMarshalledProperties(new ByteSequence(marshalledBytes));
    }
    amqMsg.setRedeliveryCounter(reference.getDeliveryCount() - 1);
    final byte[] replyToBytes = (byte[]) coreMessage.getObjectProperty(AMQ_MSG_REPLY_TO);
    if (replyToBytes != null) {
        setAMQMsgReplyTo(amqMsg, marshaller, replyToBytes);
    }
    final String userId = (String) coreMessage.getObjectProperty(AMQ_MSG_USER_ID);
    if (userId != null) {
        amqMsg.setUserID(userId);
    }
    final Boolean isDroppable = (Boolean) coreMessage.getObjectProperty(AMQ_MSG_DROPPABLE);
    if (isDroppable != null) {
        amqMsg.setDroppable(isDroppable);
    }
    final SimpleString dlqCause = (SimpleString) coreMessage.getObjectProperty(AMQ_MSG_DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY);
    if (dlqCause != null) {
        setAMQMsgDlqDeliveryFailureCause(amqMsg, dlqCause);
    }
    final SimpleString lastValueProperty = coreMessage.getLastValueProperty();
    if (lastValueProperty != null) {
        setAMQMsgHdrLastValueName(amqMsg, lastValueProperty);
    }
    final Set<SimpleString> props = coreMessage.getPropertyNames();
    if (props != null) {
        setAMQMsgObjectProperties(amqMsg, coreMessage, props, consumer);
    }
    if (bytes != null) {
        ByteSequence content = new ByteSequence(bytes);
        amqMsg.setContent(content);
    }
    return amqMsg;
}
Also used : ActiveMQMapMessage(org.apache.activemq.command.ActiveMQMapMessage) ProducerId(org.apache.activemq.command.ProducerId) ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQStreamMessage(org.apache.activemq.command.ActiveMQStreamMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ActiveMQBytesMessage(org.apache.activemq.command.ActiveMQBytesMessage) ByteSequence(org.apache.activemq.util.ByteSequence) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) MessageId(org.apache.activemq.command.MessageId)

Example 8 with ActiveMQDestination

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

the class JmsQueueWildcardSendReceiveTest method testReceiveWildcardQueueEndAsterisk.

public void testReceiveWildcardQueueEndAsterisk() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createQueue(destination1String);
    ActiveMQDestination destination3 = (ActiveMQDestination) session.createQueue(destination3String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination3, destination3String);
    ActiveMQDestination destination6 = (ActiveMQDestination) session.createQueue("TEST.ONE.*");
    consumer = session.createConsumer(destination6);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Session(javax.jms.Session) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 9 with ActiveMQDestination

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

the class JmsQueueWildcardSendReceiveTest method testReceiveWildcardQueueEndGreaterThan.

public void testReceiveWildcardQueueEndGreaterThan() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createQueue(destination1String);
    ActiveMQDestination destination2 = (ActiveMQDestination) session.createQueue(destination2String);
    ActiveMQDestination destination3 = (ActiveMQDestination) session.createQueue(destination3String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination2, destination2String);
    sendMessage(session, destination3, destination3String);
    ActiveMQDestination destination7 = (ActiveMQDestination) session.createQueue("TEST.ONE.>");
    consumer = session.createConsumer(destination7);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Session(javax.jms.Session) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 10 with ActiveMQDestination

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

the class QueueSubscriptionTest method doMultipleClientsTest.

public void doMultipleClientsTest() throws Exception {
    // Create destination
    final ActiveMQDestination dest = createDestination();
    // Create consumers
    ActiveMQConnectionFactory consumerFactory = (ActiveMQConnectionFactory) createConnectionFactory();
    consumerFactory.getPrefetchPolicy().setAll(prefetchCount);
    startConsumers(consumerFactory, dest);
    startProducers(dest, messageCount);
    // Wait for messages to be received. Make it proportional to the
    // messages delivered.
    int totalMessageCount = messageCount * producerCount;
    if (dest.isTopic()) {
        totalMessageCount *= consumerCount;
    }
    waitForAllMessagesToBeReceived(totalMessageCount);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Aggregations

ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)165 Session (javax.jms.Session)62 MessageConsumer (javax.jms.MessageConsumer)49 Message (org.apache.activemq.command.Message)46 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)45 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)44 SessionInfo (org.apache.activemq.command.SessionInfo)44 ProducerInfo (org.apache.activemq.command.ProducerInfo)42 Test (org.junit.Test)41 Message (javax.jms.Message)40 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)40 TextMessage (javax.jms.TextMessage)31 BasicOpenWireTest (org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest)24 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)22 MessageProducer (javax.jms.MessageProducer)18 XATransactionId (org.apache.activemq.command.XATransactionId)15 CountDownLatch (java.util.concurrent.CountDownLatch)14 ActiveMQMessageProducer (org.apache.activemq.ActiveMQMessageProducer)12 MessageAck (org.apache.activemq.command.MessageAck)12 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)11