Search in sources :

Example 31 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class TransactionRegistry method addToTransaction.

private void addToTransaction(String txnId, long deliveryId, DeliveryStateIF deliveryStateIF) throws EndWithErrorException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", deliveryId=" + deliveryId + ", deliveryStateIF=" + deliveryStateIF);
    lock.lock();
    try {
        ActiveTxEntry activeTxEntry = (ActiveTxEntry) activeTx.get(txnId);
        if (activeTxEntry == null) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", not found!");
            throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Transaction id not found: " + txnId));
        }
        if (activeTxEntry.outboundTxEntryMap == null)
            activeTxEntry.outboundTxEntryMap = new HashMap();
        OutboundTxEntry outboundTxEntry = (OutboundTxEntry) activeTxEntry.outboundTxEntryMap.get(deliveryId);
        if (outboundTxEntry == null) {
            outboundTxEntry = new OutboundTxEntry(null, null, deliveryStateIF);
            activeTxEntry.outboundTxEntryMap.put(deliveryId, outboundTxEntry);
        } else
            outboundTxEntry.deliveryStateIF = deliveryStateIF;
    } finally {
        lock.unlock();
    }
}
Also used : HashMap(java.util.HashMap) AMQPString(com.swiftmq.amqp.v100.types.AMQPString)

Example 32 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class ReceiverNonTransactedDurable method main.

public static void main(String[] args) {
    if (args.length == 1 && args[0].equals("?")) {
        System.out.println();
        System.out.println("Usage: <host> <port> <source> <nmsgs> <qos> <containerid> <durablelinkname> <keep> <authanon> [<username> <password>]");
        System.out.println("       <qos> ::= AT_LEAST_ONCE | AT_MOST_ONCE | EXACTLY_ONCE");
        System.out.println("       Suppress <username> <password> and set <authanon> to false to avoid SASL.");
        System.out.println();
        System.exit(0);
    }
    String host = "localhost";
    int port = 5672;
    String source = "testtopic";
    int nMsgs = 100;
    String qosS = "EXACTLY_ONCE";
    String cid = "testcid";
    String durableName = "testdurable";
    boolean keepDurable = false;
    boolean authAnon = true;
    String user = null;
    String password = null;
    if (args.length >= 1)
        host = args[0];
    if (args.length >= 2)
        port = Integer.parseInt(args[1]);
    if (args.length >= 3)
        source = args[2];
    if (args.length >= 4)
        nMsgs = Integer.parseInt(args[3]);
    if (args.length >= 5)
        qosS = args[4];
    if (args.length >= 6)
        cid = args[5];
    if (args.length >= 7)
        durableName = args[6];
    if (args.length >= 8)
        keepDurable = Boolean.parseBoolean(args[7]);
    if (args.length >= 9)
        authAnon = Boolean.parseBoolean(args[8]);
    if (args.length >= 10)
        user = args[9];
    if (args.length >= 11)
        password = args[10];
    System.out.println();
    System.out.println("Host        : " + host);
    System.out.println("Port        : " + port);
    System.out.println("Source      : " + source);
    System.out.println("Number Msgs : " + nMsgs);
    System.out.println("QoS         : " + qosS);
    System.out.println("Container Id: " + cid);
    System.out.println("Durable Name: " + durableName);
    System.out.println("Keep Durable: " + keepDurable);
    System.out.println("Auth as Anon: " + authAnon);
    System.out.println("User        : " + user);
    System.out.println("Password    : " + password);
    System.out.println();
    try {
        // Create connection and connect
        AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
        Connection connection = null;
        if (args.length < 10)
            connection = new Connection(ctx, host, port, authAnon);
        else
            connection = new Connection(ctx, host, port, user, password);
        connection.setContainerId(cid);
        if (port == 5671) {
            System.out.println("Using SSL on port 5671");
            connection.setSocketFactory(new JSSESocketFactory());
        }
        connection.connect();
        // Create session and consumer
        Session session = connection.createSession(50, 50);
        DurableConsumer c = session.createDurableConsumer(durableName, source, 100, toIntQoS(qosS), false, null);
        // Receive messages non-transacted
        for (int i = 0; i < nMsgs; i++) {
            AMQPMessage msg = c.receive();
            if (msg == null)
                break;
            AmqpValue value = msg.getAmqpValue();
            System.out.println("Received: " + ((AMQPString) value.getValue()).getValue());
            if (!msg.isSettled())
                msg.accept();
        }
        // Close everything down
        Thread.sleep(2000);
        c.close();
        if (!keepDurable)
            c.unsubscribe();
        session.close();
        connection.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Connection(com.swiftmq.amqp.v100.client.Connection) AMQPContext(com.swiftmq.amqp.AMQPContext) DurableConsumer(com.swiftmq.amqp.v100.client.DurableConsumer) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) JSSESocketFactory(com.swiftmq.net.JSSESocketFactory) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue) Session(com.swiftmq.amqp.v100.client.Session)

Example 33 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-client by iitsoftware.

the class OpenFrame method decode.

private void decode() throws Exception {
    List l = body.getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'containerId' in 'Open' frame is NULL");
    try {
        containerId = (AMQPString) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'containerId' in 'Open' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            hostname = (AMQPString) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'hostname' in 'Open' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            maxFrameSize = (AMQPUnsignedInt) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'maxFrameSize' in 'Open' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            channelMax = (AMQPUnsignedShort) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'channelMax' in 'Open' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            idleTimeOut = new Milliseconds(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'idleTimeOut' in 'Open' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            outgoingLocales = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'outgoingLocales' in 'Open' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            incomingLocales = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'incomingLocales' in 'Open' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            offeredCapabilities = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'offeredCapabilities' in 'Open' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            desiredCapabilities = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'desiredCapabilities' in 'Open' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            properties = new Fields(((AMQPMap) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'properties' in 'Open' frame: " + e);
    }
}
Also used : Fields(com.swiftmq.amqp.v100.generated.transport.definitions.Fields) List(java.util.List) ArrayList(java.util.ArrayList) Milliseconds(com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds) IOException(java.io.IOException)

Example 34 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-client by iitsoftware.

the class AMQPRepo method remove.

AMQPRepo remove(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("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("Removed 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 35 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class ReceiveTester method test.

public void test() {
    try {
        Connection connection = Util.createConnection();
        Session session = Util.createSession(connection);
        Producer producer = session.createProducer(address, qos);
        for (int i = 0; i < nMsgs; i++) {
            AMQPMessage msg = messageFactory.create(i);
            Map map = new HashMap();
            map.put(new AMQPString(PROPNAME), new AMQPInt(i));
            msg.setApplicationProperties(new ApplicationProperties(map));
            producer.send(msg, persistent, 5, -1);
        }
        Consumer consumer = session.createConsumer(address, 500, qos, true, null);
        for (int i = 0; i < nMsgs; i++) {
            AMQPMessage msg = consumer.receive(1000);
            if (msg != null) {
                messageFactory.verify(msg);
                if (!msg.isSettled())
                    msg.accept();
                receiveVerifier.add(msg);
            } else
                throw new Exception("message is null");
        }
        connection.close();
        DeliveryMemory deliveryMemory = consumer.getDeliveryMemory();
        System.out.println("Unsettled: " + deliveryMemory.getNumberUnsettled());
        connection = Util.createConnection();
        session = Util.createSession(connection);
        Consumer consumerRecover = session.createConsumer(address, 500, qos, true, null, deliveryMemory);
        consumerRecover.close();
        session.close();
        connection.close();
        connection = Util.createConnection();
        session = Util.createSession(connection);
        consumer = session.createConsumer(address, 500, qos, true, null);
        for (; ; ) {
            AMQPMessage msg = consumer.receive(1000);
            if (msg != null) {
                messageFactory.verify(msg);
                if (!msg.isSettled())
                    msg.accept();
                receiveVerifier.add(msg);
            } else
                break;
        }
        consumer.close();
        session.close();
        connection.close();
        receiveVerifier.verify();
    } catch (Exception e) {
        e.printStackTrace();
        fail("test failed: " + e);
    }
}
Also used : HashMap(java.util.HashMap) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPInt(com.swiftmq.amqp.v100.types.AMQPInt) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

AMQPString (com.swiftmq.amqp.v100.types.AMQPString)29 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)24 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)17 HashMap (java.util.HashMap)14 Map (java.util.Map)14 IOException (java.io.IOException)13 AMQPContext (com.swiftmq.amqp.AMQPContext)9 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)8 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)8 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)6 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)6 QueueException (com.swiftmq.swiftlet.queue.QueueException)5 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)4 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)4 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)4 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)4 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)4 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)4 Iterator (java.util.Iterator)4 Connection (com.swiftmq.amqp.v100.client.Connection)3