Search in sources :

Example 1 with Data

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Data 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 2 with Data

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Data in project swiftmq-ce by iitsoftware.

the class DataMessageFactory method createReplyMessage.

public AMQPMessage createReplyMessage(AMQPMessage request) throws Exception {
    AMQPMessage reply = new AMQPMessage();
    List data = request.getData();
    for (int i = 0; i < data.size(); i++) reply.addData((Data) data.get(i));
    return reply;
}
Also used : List(java.util.List) Data(com.swiftmq.amqp.v100.generated.messaging.message_format.Data) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 3 with Data

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Data in project swiftmq-client by iitsoftware.

the class EndpointImpl method poll.

public void poll() {
    try {
        AMQPMessage msg = consumer.receiveNoWait(this);
        if (msg != null) {
            Data data = msg.getData().get(0);
            dis.reset();
            dis.setBuffer(data.getValue());
            Dumpable d = Dumpalizer.construct(dis, factory);
            if (d instanceof Reply)
                requestRegistry.setReply((Reply) d);
            else
                dispatch((Request) d);
            pollerService.execute(poller);
        }
    } catch (Exception e) {
        e.printStackTrace();
        close();
    }
}
Also used : Data(com.swiftmq.amqp.v100.generated.messaging.message_format.Data) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) Dumpable(com.swiftmq.tools.dump.Dumpable)

Example 4 with Data

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Data in project swiftmq-client by iitsoftware.

the class EndpointImpl method performRequest.

public synchronized void performRequest(Request request) {
    try {
        dos.rewind();
        Dumpalizer.dump(dos, request);
        AMQPMessage msg = new AMQPMessage();
        byte[] bytes = new byte[dos.getCount()];
        System.arraycopy(dos.getBuffer(), 0, bytes, 0, bytes.length);
        msg.addData(new Data(bytes));
        Properties prop = new Properties();
        if (connection.getUserName() == null)
            prop.setUserId(new AMQPBinary("anonymous".getBytes()));
        else
            prop.setUserId(new AMQPBinary(connection.getUserName().getBytes()));
        prop.setReplyTo(replyAddress);
        msg.setProperties(prop);
        producer.send(msg);
    } catch (Exception e) {
        close();
    }
}
Also used : Data(com.swiftmq.amqp.v100.generated.messaging.message_format.Data) AMQPBinary(com.swiftmq.amqp.v100.types.AMQPBinary) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 5 with Data

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Data in project rabbitmq-stream-java-client by rabbitmq.

the class SwiftMqCodec method encode.

@Override
public EncodedMessage encode(Message message) {
    AMQPMessage outboundMessage;
    if (message instanceof SwiftMqAmqpMessageWrapper) {
        outboundMessage = ((SwiftMqAmqpMessageWrapper) message).message;
    } else {
        outboundMessage = new AMQPMessage();
        if (message.getProperties() != null) {
            com.rabbitmq.stream.Properties headers = message.getProperties();
            com.swiftmq.amqp.v100.generated.messaging.message_format.Properties properties = new com.swiftmq.amqp.v100.generated.messaging.message_format.Properties();
            boolean propertiesSet = false;
            if (headers.getMessageId() != null) {
                if (headers.getMessageId() instanceof String) {
                    properties.setMessageId(new MessageIdString(headers.getMessageIdAsString()));
                } else if (headers.getMessageId().getClass().isPrimitive() || headers.getMessageId() instanceof Long) {
                    properties.setMessageId(new MessageIdUlong(headers.getMessageIdAsLong()));
                } else if (headers.getMessageId().getClass().isArray()) {
                    properties.setMessageId(new MessageIdBinary(headers.getMessageIdAsBinary()));
                } else if (headers.getMessageId() instanceof UUID) {
                    properties.setMessageId(new MessageIdUuid(headers.getMessageIdAsUuid()));
                } else {
                    throw new IllegalStateException("Type not supported for message ID:" + properties.getMessageId().getClass());
                }
                propertiesSet = true;
            }
            if (headers.getUserId() != null) {
                properties.setUserId(new AMQPBinary(headers.getUserId()));
                propertiesSet = true;
            }
            if (headers.getTo() != null) {
                properties.setTo(new AddressString(headers.getTo()));
                propertiesSet = true;
            }
            if (headers.getSubject() != null) {
                properties.setSubject(new AMQPString(headers.getSubject()));
                propertiesSet = true;
            }
            if (headers.getReplyTo() != null) {
                properties.setReplyTo(new AddressString(headers.getReplyTo()));
                propertiesSet = true;
            }
            if (headers.getCorrelationId() != null) {
                if (headers.getCorrelationId() instanceof String) {
                    properties.setCorrelationId(new MessageIdString(headers.getCorrelationIdAsString()));
                } else if (headers.getCorrelationId().getClass().isPrimitive() || headers.getCorrelationId() instanceof Long) {
                    properties.setCorrelationId(new MessageIdUlong(headers.getCorrelationIdAsLong()));
                } else if (headers.getCorrelationId().getClass().isArray()) {
                    properties.setCorrelationId(new MessageIdBinary(headers.getCorrelationIdAsBinary()));
                } else if (headers.getCorrelationId() instanceof UUID) {
                    properties.setCorrelationId(new MessageIdUuid(headers.getCorrelationIdAsUuid()));
                } else {
                    throw new IllegalStateException("Type not supported for correlation ID:" + properties.getCorrelationId().getClass());
                }
                propertiesSet = true;
            }
            if (headers.getContentType() != null) {
                properties.setContentType(new AMQPSymbol(headers.getContentType()));
                propertiesSet = true;
            }
            if (headers.getContentEncoding() != null) {
                properties.setContentEncoding(new AMQPSymbol(headers.getContentEncoding()));
                propertiesSet = true;
            }
            if (headers.getAbsoluteExpiryTime() > 0) {
                properties.setAbsoluteExpiryTime(new AMQPTimestamp(headers.getAbsoluteExpiryTime()));
                propertiesSet = true;
            }
            if (headers.getCreationTime() > 0) {
                properties.setCreationTime(new AMQPTimestamp(headers.getCreationTime()));
                propertiesSet = true;
            }
            if (headers.getGroupId() != null) {
                properties.setGroupId(new AMQPString(headers.getGroupId()));
                propertiesSet = true;
            }
            if (headers.getGroupSequence() >= 0) {
                properties.setGroupSequence(new SequenceNo(headers.getGroupSequence()));
                propertiesSet = true;
            }
            if (headers.getReplyToGroupId() != null) {
                properties.setReplyToGroupId(new AMQPString(headers.getReplyToGroupId()));
                propertiesSet = true;
            }
            if (propertiesSet) {
                outboundMessage.setProperties(properties);
            }
        }
        if (message.getApplicationProperties() != null && !message.getApplicationProperties().isEmpty()) {
            Map<AMQPType, AMQPType> applicationProperties = new LinkedHashMap<>(message.getApplicationProperties().size());
            for (Map.Entry<String, Object> entry : message.getApplicationProperties().entrySet()) {
                applicationProperties.put(new AMQPString(entry.getKey()), convertToSwiftMqType(entry.getValue()));
            }
            try {
                outboundMessage.setApplicationProperties(new ApplicationProperties(applicationProperties));
            } catch (IOException e) {
                throw new StreamException("Error while setting application properties", e);
            }
        }
        if (message.getMessageAnnotations() != null && !message.getMessageAnnotations().isEmpty()) {
            Map<AMQPType, AMQPType> messageAnnotations = new LinkedHashMap<>(message.getMessageAnnotations().size());
            for (Map.Entry<String, Object> entry : message.getMessageAnnotations().entrySet()) {
                messageAnnotations.put(new AMQPSymbol(entry.getKey()), convertToSwiftMqType(entry.getValue()));
            }
            try {
                outboundMessage.setMessageAnnotations(new MessageAnnotations(messageAnnotations));
            } catch (IOException e) {
                throw new StreamException("Error while setting message annotations", e);
            }
        }
        if (message.getBodyAsBinary() != null) {
            outboundMessage.addData(new Data(message.getBodyAsBinary()));
        }
    }
    try {
        int bufferSize;
        // FIXME estimate the size with all message data
        if (outboundMessage.getData() != null && !outboundMessage.getData().isEmpty()) {
            bufferSize = outboundMessage.getData().get(0).getPredictedSize();
        } else {
            bufferSize = 8192;
        }
        DataByteArrayOutputStream output = new DataByteArrayOutputStream(bufferSize);
        outboundMessage.writeContent(output);
        return new EncodedMessage(output.getCount(), output.getBuffer());
    } catch (IOException e) {
        throw new StreamException("Error while writing AMQP 1.0 message to output stream");
    }
}
Also used : SequenceNo(com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo) DataByteArrayOutputStream(com.swiftmq.tools.util.DataByteArrayOutputStream) com.swiftmq.amqp.v100.generated.messaging.message_format(com.swiftmq.amqp.v100.generated.messaging.message_format) LinkedHashMap(java.util.LinkedHashMap) StreamException(com.rabbitmq.stream.StreamException) UUID(java.util.UUID) com.rabbitmq.stream.amqp(com.rabbitmq.stream.amqp) IOException(java.io.IOException) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Data (com.swiftmq.amqp.v100.generated.messaging.message_format.Data)8 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)8 IOException (java.io.IOException)5 StreamException (com.rabbitmq.stream.StreamException)2 AmqpSequence (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence)2 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)2 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)2 AMQPFrame (com.swiftmq.amqp.v100.transport.AMQPFrame)2 HeartbeatFrame (com.swiftmq.amqp.v100.transport.HeartbeatFrame)2 Dumpable (com.swiftmq.tools.dump.Dumpable)2 List (java.util.List)2 Map (java.util.Map)2 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 MessageFormat (com.swiftmq.amqp.v100.generated.transport.definitions.MessageFormat)1 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)1 AMQPBinary (com.swiftmq.amqp.v100.types.AMQPBinary)1 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)1 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)1