Search in sources :

Example 1 with SequenceNo

use of com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo in project swiftmq-ce by iitsoftware.

the class AMQPValueMapMessageFactory method create.

public AMQPMessage create(int sequenceNo) throws Exception {
    AMQPMessage msg = new AMQPMessage();
    Map map = new HashMap();
    map.put(new AMQPString("key1"), new AMQPString("value1"));
    map.put(new AMQPLong(Integer.MAX_VALUE + 1), new AMQPLong(200));
    map.put(new AMQPString("key3"), new AMQPString("value1"));
    map.put(new AMQPLong(Integer.MAX_VALUE + 2), new AMQPLong(400));
    msg.setAmqpValue(new AmqpValue(new AMQPMap(map)));
    return msg;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) AMQPLong(com.swiftmq.amqp.v100.types.AMQPLong) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) Map(java.util.Map) HashMap(java.util.HashMap) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 2 with SequenceNo

use of com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo in project swiftmq-ce by iitsoftware.

the class AMQPValueStringMessageFactory method create.

public AMQPMessage create(int sequenceNo) throws Exception {
    AMQPMessage msg = new AMQPMessage();
    msg.setAmqpValue(new AmqpValue(new AMQPString("Message #" + sequenceNo)));
    return msg;
}
Also used : AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 3 with SequenceNo

use of com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo in project swiftmq-ce by iitsoftware.

the class DataMessageFactory method create.

public AMQPMessage create(int sequenceNo) throws Exception {
    AMQPMessage msg = new AMQPMessage();
    msg.addData(new Data(b));
    msg.addData(new Data(b));
    msg.addData(new Data(b));
    return msg;
}
Also used : Data(com.swiftmq.amqp.v100.generated.messaging.message_format.Data) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 4 with SequenceNo

use of com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo in project swiftmq-ce by iitsoftware.

the class JMSMappingOutboundTransformer method transform.

public void transform(Delivery delivery) throws AMQPException, JMSException {
    jmsTypeProp = getValue(PROP_JMS_TYPE, null);
    MessageImpl message = delivery.getMessage();
    if (message.propertyExists(amqpNative) && message.getBooleanProperty(amqpNative))
        throw new JMSException("Message is an AMQP native transformation");
    try {
        AMQPMessage amqpMessage = new AMQPMessage();
        Header header = new Header();
        int deliveryMode = message.getJMSDeliveryMode();
        header.setDurable(new AMQPBoolean(deliveryMode == DeliveryMode.PERSISTENT));
        header.setPriority(new AMQPUnsignedByte(message.getJMSPriority()));
        header.setDeliveryCount(new AMQPUnsignedInt(delivery.getMessageIndex().getDeliveryCount() - 1));
        long ttl = message.getJMSExpiration();
        if (ttl > 0) {
            if (message.propertyExists(Util.PROP_EXPIRATION_CURRENT_TIME_ADD))
                header.setTtl(new Milliseconds(ttl - message.getLongProperty(Util.PROP_EXPIRATION_CURRENT_TIME_ADD)));
        }
        Properties properties = new Properties();
        String messageId = message.getJMSMessageID();
        if (messageId != null)
            properties.setMessageId(new MessageIdString(message.getJMSMessageID()));
        if (message.propertyExists(Util.PROP_AMQP_TO_ADDRESS))
            properties.setTo(new AddressString(message.getStringProperty(Util.PROP_AMQP_TO_ADDRESS)));
        else
            properties.setTo(new AddressString(message.getJMSDestination().toString()));
        Destination replyTo = message.getJMSReplyTo();
        if (replyTo != null)
            properties.setReplyTo(new AddressString(replyTo.toString()));
        String correlationId = message.getJMSCorrelationID();
        if (correlationId != null)
            properties.setCorrelationId(new MessageIdString(correlationId));
        if (ttl > 0)
            properties.setAbsoluteExpiryTime(new AMQPTimestamp(ttl));
        long timestamp = message.getJMSTimestamp();
        if (timestamp > 0)
            properties.setCreationTime(new AMQPTimestamp(timestamp));
        Map daMap = null;
        Map maMap = null;
        Map ftMap = null;
        Map apMap = null;
        String firstAcquirerName = prefixVendor + "FirstAcquirer";
        String subject = prefixVendor + "Subject";
        String contentType = prefixVendor + "ContentType";
        String contentEncoding = prefixVendor + "ContentEncoding";
        String replyToGroupId = prefixVendor + "ReplyToGroupID";
        for (Enumeration _enum = message.getPropertyNames(); _enum.hasMoreElements(); ) {
            String name = (String) _enum.nextElement();
            if (name.equals(amqpNative) || name.equals(messageFormat) || name.equals(Util.PROP_EXPIRATION_CURRENT_TIME_ADD) || name.equals(Util.PROP_AMQP_TO_ADDRESS))
                continue;
            if (name.equals(firstAcquirerName))
                header.setFirstAcquirer(new AMQPBoolean(message.getBooleanProperty(firstAcquirerName)));
            else if (name.equals(MessageImpl.PROP_USER_ID))
                properties.setUserId(new AMQPBinary(message.getStringProperty(MessageImpl.PROP_USER_ID).getBytes()));
            else if (name.equals(subject))
                properties.setSubject(new AMQPString(message.getStringProperty(subject)));
            else if (name.equals(contentType))
                properties.setContentType(new AMQPSymbol(message.getStringProperty(contentType)));
            else if (name.equals(contentEncoding))
                properties.setContentEncoding(new AMQPSymbol(message.getStringProperty(contentEncoding)));
            else if (name.equals("JMSXGroupID") && message.getObjectProperty(Util.PROP_GROUP_ID) instanceof String)
                properties.setGroupId(new AMQPString(message.getStringProperty(Util.PROP_GROUP_ID)));
            else if (name.equals("JMSXGroupSeq") && message.getObjectProperty(Util.PROP_GROUP_SEQ) instanceof Long)
                properties.setGroupSequence(new SequenceNo(message.getLongProperty(Util.PROP_GROUP_SEQ)));
            else if (name.equals(replyToGroupId))
                properties.setReplyToGroupId(new AMQPString(message.getStringProperty(replyToGroupId)));
            else if (name.startsWith(prefixDA)) {
                if (daMap == null)
                    daMap = new HashMap();
                daMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixDA.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
            } else if (name.startsWith(prefixMA)) {
                if (maMap == null)
                    maMap = new HashMap();
                maMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixMA.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
            } else if (name.startsWith(prefixFT)) {
                if (ftMap == null)
                    ftMap = new HashMap();
                ftMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixFT.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
            } else {
                if (apMap == null)
                    apMap = new HashMap();
                apMap.put(new AMQPString(nameTranslator.translate(name)), Util.convertJMStoAMQP(message.getObjectProperty(name)));
            }
        }
        if (message.getJMSType() != null) {
            if (jmsTypeProp != null) {
                if (apMap == null)
                    apMap = new HashMap();
                apMap.put(new AMQPString(jmsTypeProp), Util.convertJMStoAMQP(message.getJMSType()));
            } else {
                if (maMap == null)
                    maMap = new HashMap();
                maMap.put(new AMQPSymbol("x-opt-jms-type"), new AMQPString(message.getJMSType()));
            }
        }
        amqpMessage.setHeader(header);
        amqpMessage.setProperties(properties);
        if (daMap != null)
            amqpMessage.setDeliveryAnnotations(new DeliveryAnnotations(daMap));
        if (maMap != null)
            amqpMessage.setMessageAnnotations(new MessageAnnotations(maMap));
        if (apMap != null)
            amqpMessage.setApplicationProperties(new ApplicationProperties(apMap));
        if (ftMap != null)
            amqpMessage.setFooter(new Footer(ftMap));
        bodyFactory.createBody(message, amqpMessage);
        delivery.setAmqpMessage(amqpMessage);
        dbos.rewind();
        amqpMessage.writeContent(dbos);
        byte[] payload = new byte[dbos.getCount()];
        System.arraycopy(dbos.getBuffer(), 0, payload, 0, dbos.getCount());
        delivery.setData(payload);
        delivery.setMessageFormat(0);
    } catch (IOException e) {
        e.printStackTrace();
        throw new AMQPException(e.toString());
    }
}
Also used : Destination(javax.jms.Destination) SequenceNo(com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) HashMap(java.util.HashMap) JMSException(javax.jms.JMSException) Enumeration(java.util.Enumeration) IOException(java.io.IOException) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) Milliseconds(com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds) MessageImpl(com.swiftmq.jms.MessageImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with SequenceNo

use of com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo in project swiftmq-client by iitsoftware.

the class Properties method decode.

private void decode() throws Exception {
    List l = getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : MessageIdFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        messageId = MessageIdFactory.create(t);
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            userId = (AMQPBinary) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'userId' in 'Properties' type: " + e);
    }
    // Factory  : AddressFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        to = AddressFactory.create(t);
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            subject = (AMQPString) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'subject' in 'Properties' type: " + e);
    }
    // Factory  : AddressFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        replyTo = AddressFactory.create(t);
    // Factory  : MessageIdFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        correlationId = MessageIdFactory.create(t);
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            contentType = (AMQPSymbol) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'contentType' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            contentEncoding = (AMQPSymbol) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'contentEncoding' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            absoluteExpiryTime = (AMQPTimestamp) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'absoluteExpiryTime' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            creationTime = (AMQPTimestamp) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'creationTime' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            groupId = (AMQPString) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'groupId' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            groupSequence = new SequenceNo(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'groupSequence' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            replyToGroupId = (AMQPString) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'replyToGroupId' in 'Properties' type: " + e);
    }
}
Also used : SequenceNo(com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)7 IOException (java.io.IOException)6 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)5 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)3 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 AMQPLong (com.swiftmq.amqp.v100.types.AMQPLong)2 HashMap (java.util.HashMap)2 JMSException (javax.jms.JMSException)2 StreamException (com.rabbitmq.stream.StreamException)1 com.rabbitmq.stream.amqp (com.rabbitmq.stream.amqp)1 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)1 com.swiftmq.amqp.v100.generated.messaging.message_format (com.swiftmq.amqp.v100.generated.messaging.message_format)1 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 AmqpSequence (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence)1 Data (com.swiftmq.amqp.v100.generated.messaging.message_format.Data)1 Coordinator (com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator)1 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)1