Search in sources :

Example 1 with AddressIF

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

the class ReplierNonTransacted 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> <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 = "testqueue";
    int nMsgs = 100;
    String qosS = "EXACTLY_ONCE";
    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)
        authAnon = Boolean.parseBoolean(args[5]);
    if (args.length >= 7)
        user = args[6];
    if (args.length >= 8)
        password = args[7];
    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("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 < 7)
            connection = new Connection(ctx, host, port, authAnon);
        else
            connection = new Connection(ctx, host, port, user, password);
        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);
        Consumer c = session.createConsumer(source, 100, toIntQoS(qosS), true, null);
        // Receive messages non-transacted
        for (int i = 0; i < nMsgs; i++) {
            AMQPMessage request = c.receive();
            if (request == null)
                break;
            AmqpValue value = request.getAmqpValue();
            System.out.println("Received: " + ((AMQPString) value.getValue()).getValue());
            if (!request.isSettled())
                request.accept();
            Properties prop = request.getProperties();
            if (prop == null)
                throw new Exception("Properties not set in request: " + request);
            AddressIF replyTo = prop.getReplyTo();
            Producer p = session.createProducer(replyTo.getValueString(), toIntQoS(qosS));
            AMQPMessage reply = new AMQPMessage();
            Properties prop2 = new Properties();
            prop2.setTo(replyTo);
            prop2.setCorrelationId(prop.getMessageId());
            reply.setProperties(prop2);
            String s = "RE: " + ((AMQPString) value.getValue()).getValue();
            reply.setAmqpValue(new AmqpValue(new AMQPString(s)));
            System.out.println("Send: " + s);
            p.send(reply);
            p.close();
        }
        // Close everything down
        Thread.sleep(2000);
        c.close();
        session.close();
        connection.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AddressIF(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue) AMQPContext(com.swiftmq.amqp.AMQPContext) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) JSSESocketFactory(com.swiftmq.net.JSSESocketFactory)

Example 2 with AddressIF

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

the class Replier method serviceRequests.

public void serviceRequests() {
    try {
        for (int i = 0; i < nMsgs; i++) {
            TxnIdIF txnIdIF = txc.createTxnId();
            AMQPMessage request = consumer.receive();
            request.setTxnIdIF(txnIdIF);
            if (request != null) {
                messageFactory.verify(request);
                if (!request.isSettled())
                    request.accept();
                Properties prop = request.getProperties();
                if (prop == null)
                    throw new Exception("Properties not set in request: " + request);
                AddressIF replyTo = prop.getReplyTo();
                if (replyTo == null)
                    throw new Exception("replyTo not set in request: " + request);
                Producer p = getSession().createProducer(replyTo.getValueString(), qos);
                AMQPMessage reply = messageFactory.createReplyMessage(request);
                reply.setTxnIdIF(txnIdIF);
                Properties prop2 = new Properties();
                prop2.setTo(replyTo);
                prop2.setCorrelationId(prop.getMessageId());
                reply.setProperties(prop2);
                p.send(reply);
                p.close();
            } else
                throw new Exception("Msg == null at i=" + i);
            txc.commit(txnIdIF);
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) AddressIF(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF) Producer(com.swiftmq.amqp.v100.client.Producer) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 3 with AddressIF

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

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

the class Replier method serviceRequests.

public void serviceRequests() {
    try {
        for (int i = 0; i < nMsgs; i++) {
            TxnIdIF txnIdIF = txc.createTxnId();
            consumer.acquire(1, txnIdIF);
            AMQPMessage request = consumer.receive();
            if (request != null) {
                messageFactory.verify(request);
                if (!request.isSettled())
                    request.accept();
                Properties prop = request.getProperties();
                if (prop == null)
                    throw new Exception("Properties not set in request: " + request);
                AddressIF replyTo = prop.getReplyTo();
                if (replyTo == null)
                    throw new Exception("replyTo not set in request: " + request);
                Producer p = getSession().createProducer(replyTo.getValueString(), qos);
                AMQPMessage reply = messageFactory.createReplyMessage(request);
                reply.setTxnIdIF(txnIdIF);
                Properties prop2 = new Properties();
                prop2.setTo(replyTo);
                prop2.setCorrelationId(prop.getMessageId());
                reply.setProperties(prop2);
                p.send(reply);
                p.close();
            } else
                throw new Exception("Msg == null at i=" + i);
            txc.commit(txnIdIF);
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) AddressIF(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF) Producer(com.swiftmq.amqp.v100.client.Producer) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 5 with AddressIF

use of com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF 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();
            consumer.acquire(1, txnIdIF);
            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)

Aggregations

AddressIF (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF)12 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)12 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)12 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)8 Producer (com.swiftmq.amqp.v100.client.Producer)5 AMQPContext (com.swiftmq.amqp.AMQPContext)2 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)2 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)2 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)2 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)1 JMSException (javax.jms.JMSException)1