Search in sources :

Example 11 with Properties

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

the class AMQPRepo method add.

AMQPRepo add(File file, String appname) throws Exception {
    String filename = file.getName();
    String content = loadFile(file);
    AMQPMessage request = new AMQPMessage();
    Map propMap = new HashMap();
    propMap.put(new AMQPString("app"), new AMQPString(appname));
    propMap.put(new AMQPString("file"), new AMQPString(filename));
    propMap.put(new AMQPString("operation"), new AMQPString("add"));
    request.setApplicationProperties(new ApplicationProperties(propMap));
    Properties properties = new Properties();
    properties.setReplyTo(replyQueue);
    request.setProperties(properties);
    request.setAmqpValue(new AmqpValue(new AMQPString(content)));
    producer.send(request);
    AMQPMessage reply = consumer.receive(TIMEOUT);
    if (reply == null)
        throw new Exception("Timeout occurred while waiting for a reply!");
    AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
    boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
    if (success)
        System.out.println(filename + " added to repository " + appname);
    else {
        String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
        System.out.println(result);
    }
    return this;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) Map(java.util.Map) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 12 with Properties

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

the class AMQPRepo method remove.

AMQPRepo remove(File file, String appname) throws Exception {
    String filename = file.getName();
    AMQPMessage request = new AMQPMessage();
    Map propMap = new HashMap();
    propMap.put(new AMQPString("app"), new AMQPString(appname));
    propMap.put(new AMQPString("file"), new AMQPString(filename));
    propMap.put(new AMQPString("operation"), new AMQPString("remove"));
    request.setApplicationProperties(new ApplicationProperties(propMap));
    Properties properties = new Properties();
    properties.setReplyTo(replyQueue);
    request.setProperties(properties);
    producer.send(request);
    AMQPMessage reply = consumer.receive(TIMEOUT);
    if (reply == null)
        throw new Exception("Timeout occurred while waiting for a reply!");
    AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
    boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
    if (success)
        System.out.println(filename + " removed from repository " + appname);
    else {
        String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
        System.out.println(result);
    }
    return this;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with Properties

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

the class AMQPRepo method list.

AMQPRepo list(String appname) throws Exception {
    AMQPMessage request = new AMQPMessage();
    Map propMap = new HashMap();
    propMap.put(new AMQPString("app"), new AMQPString(appname));
    propMap.put(new AMQPString("operation"), new AMQPString("list"));
    request.setApplicationProperties(new ApplicationProperties(propMap));
    Properties properties = new Properties();
    properties.setReplyTo(replyQueue);
    request.setProperties(properties);
    producer.send(request);
    AMQPMessage reply = consumer.receive(TIMEOUT);
    if (reply == null)
        throw new Exception("Timeout occurred while waiting for a reply!");
    AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
    boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
    if (success) {
        System.out.println("Content of repository " + appname + ":");
        System.out.println();
        int n = Integer.parseInt(((AMQPString) (body.getValue().get(new AMQPString("nfiles")))).getValue());
        for (int i = 0; i < n; i++) System.out.println(((AMQPString) (body.getValue().get(new AMQPString("storetime" + i)))).getValue() + "\t" + ((AMQPString) (body.getValue().get(new AMQPString("file" + i)))).getValue());
        System.out.println();
    } else {
        String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
        System.out.println(result);
    }
    return this;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with Properties

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties 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)

Example 15 with Properties

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

the class Producer method send.

/**
 * Send a message to the target. For transactional sends the method returns after settlement has been finished, otherwise when the message has been sent.
 *
 * @param msg        message
 * @param persistent whether the message should send/stored durable
 * @param priority   message priority (default is 5)
 * @param ttl        time to live (expiration) in milliseconds, default no expiration
 * @return delivery state of the message
 * @throws AMQPException on error
 */
public DeliveryStateIF send(AMQPMessage msg, boolean persistent, int priority, long ttl) throws AMQPException {
    verifyState();
    Header header = msg.getHeader();
    if (header == null) {
        header = new Header();
        msg.setHeader(header);
    }
    header.setDurable(new AMQPBoolean(persistent));
    header.setPriority(new AMQPUnsignedByte(priority));
    if (ttl >= 0)
        header.setTtl(new Milliseconds(ttl));
    Properties props = msg.getProperties();
    if (props == null) {
        props = new Properties();
        msg.setProperties(props);
    }
    if (props.getMessageId() == null)
        props.setMessageId(new MessageIdString(nextMsgId()));
    props.setTo(new AddressString(target));
    String userName = mySession.myConnection.getUserName();
    if (userName != null)
        props.setUserId(new AMQPBinary(userName.getBytes()));
    Semaphore sem = new Semaphore();
    try {
        POSendMessage po = new POSendMessage(sem, this, msg, msg.getTxnIdIF(), msg.getDeliveryTag());
        mySession.dispatch(po);
        sem.waitHere();
        if (!po.isSuccess())
            throw new AMQPException(po.getException());
        return po.getDeliveryState();
    } catch (Exception e) {
        e.printStackTrace();
        throw new AMQPException(e.toString());
    }
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) POSendMessage(com.swiftmq.amqp.v100.client.po.POSendMessage) MessageIdString(com.swiftmq.amqp.v100.generated.messaging.message_format.MessageIdString) MessageIdString(com.swiftmq.amqp.v100.generated.messaging.message_format.MessageIdString) AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) Semaphore(com.swiftmq.tools.concurrent.Semaphore) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) Milliseconds(com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds) IOException(java.io.IOException) Header(com.swiftmq.amqp.v100.generated.messaging.message_format.Header)

Aggregations

AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)22 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)19 AddressIF (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF)12 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)8 IOException (java.io.IOException)8 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)6 Map (java.util.Map)6 Producer (com.swiftmq.amqp.v100.client.Producer)5 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)5 HashMap (java.util.HashMap)5 List (java.util.List)5 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)4 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)4 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)4 ArrayList (java.util.ArrayList)4 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)3 Fields (com.swiftmq.amqp.v100.generated.transport.definitions.Fields)3 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)3 JMSException (javax.jms.JMSException)3 StreamException (com.rabbitmq.stream.StreamException)2