Search in sources :

Example 26 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.

the class Requestor method sendRequests.

public void sendRequests() {
    try {
        AddressIF tempDest = consumer.getRemoteAddress();
        for (int i = 0; i < nMsgs; i++) {
            TxnIdIF txnIdIF = txc.createTxnId();
            AMQPMessage request = messageFactory.create(i);
            request.setTxnIdIF(txnIdIF);
            Properties prop = new Properties();
            prop.setReplyTo(tempDest);
            request.setProperties(prop);
            producer.send(request, persistent, 5, -1);
            txc.commit(txnIdIF);
            txnIdIF = txc.createTxnId();
            AMQPMessage reply = consumer.receive();
            if (reply == null)
                throw new Exception("Reply is null");
            if (!reply.isSettled())
                reply.accept();
            txc.commit(txnIdIF);
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : AddressIF(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF) TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 27 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage 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 28 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage 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 29 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage 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 30 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-client by iitsoftware.

the class TransactionController method createTxnId.

/**
 * Creates a new transaction id.
 *
 * @return transaction id
 * @throws AMQPException on error
 */
public synchronized TxnIdIF createTxnId() throws AMQPException {
    if (producer == null) {
        producer = mySession.createProducer(Coordinator.DESCRIPTOR_NAME, QoS.AT_LEAST_ONCE);
        producer.setTransactionController(true);
        Set capa = producer.getDestinationCapabilities();
        if (capa != null) {
            if (capa.contains(TxnCapability.LOCAL_TRANSACTIONS.getValue()))
                supportLocalTransactions = true;
            supportDistributedTransactions = capa.contains(TxnCapability.DISTRIBUTED_TRANSACTIONS.getValue());
            supportPromotableTransactions = capa.contains(TxnCapability.PROMOTABLE_TRANSACTIONS.getValue());
            supportMultiTxnsPerSsn = capa.contains(TxnCapability.MULTI_TXNS_PER_SSN.getValue());
            supportMultiSsnsPerTxn = capa.contains(TxnCapability.MULTI_SSNS_PER_TXN.getValue());
        }
    }
    AMQPMessage msg = new AMQPMessage();
    msg.setAmqpValue(new AmqpValue(new Declare()));
    Declared declared = (Declared) producer.send(msg);
    return declared == null ? null : declared.getTxnId();
}
Also used : Set(java.util.Set) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Aggregations

AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)56 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)24 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)23 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)20 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)19 Map (java.util.Map)13 AddressIF (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF)12 HashMap (java.util.HashMap)10 AMQPContext (com.swiftmq.amqp.AMQPContext)9 Data (com.swiftmq.amqp.v100.generated.messaging.message_format.Data)8 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)8 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)8 IOException (java.io.IOException)8 Producer (com.swiftmq.amqp.v100.client.Producer)6 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)6 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)5 List (java.util.List)4 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)3 Connection (com.swiftmq.amqp.v100.client.Connection)3 Session (com.swiftmq.amqp.v100.client.Session)3