Search in sources :

Example 6 with ApplicationProperties

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

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

Example 8 with ApplicationProperties

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

the class SendTester 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);
        }
        connection.close();
        DeliveryMemory deliveryMemory = producer.getDeliveryMemory();
        System.out.println("Unsettled: " + deliveryMemory.getNumberUnsettled());
        connection = Util.createConnection();
        session = Util.createSession(connection);
        Producer producerRecover = session.createProducer(address, qos, deliveryMemory);
        producerRecover.close();
        session.close();
        connection.close();
        connection = Util.createConnection();
        session = Util.createSession(connection);
        Consumer 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)

Example 9 with ApplicationProperties

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

the class JMSMappingInboundTransformer method transformApplicationProperties.

protected void transformApplicationProperties(ApplicationProperties applicationProperties, MessageImpl jmsMessage) throws Exception {
    Map map = applicationProperties.getValue();
    for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        AMQPType key = (AMQPType) entry.getKey();
        AMQPDescribedConstructor constructor = key.getConstructor();
        int code = constructor != null ? constructor.getFormatCode() : key.getCode();
        String propName = null;
        if (AMQPTypeDecoder.isString(code))
            propName = nameTranslator.translate(((AMQPString) key).getValue());
        else if (AMQPTypeDecoder.isSymbol(code))
            propName = nameTranslator.translate(((AMQPSymbol) key).getValue());
        if (propName != null) {
            if (jmsTypeProp != null && propName.equals(jmsTypeProp)) {
                AMQPType t = (AMQPType) entry.getValue();
                if (AMQPTypeDecoder.isString(t.getCode()))
                    jmsMessage.setJMSType(((AMQPString) entry.getValue()).getValue());
                else
                    jmsMessage.setStringProperty("JMS_TYPE_ERROR", jmsTypeProp + " must be of String value");
            } else {
                try {
                    jmsMessage.setObjectProperty(propName, Util.convertAMQPtoJMS((AMQPType) entry.getValue()));
                } catch (Exception e) {
                    jmsMessage.setStringProperty(propName + "_ERROR", e.getMessage());
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) Map(java.util.Map) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) JMSException(javax.jms.JMSException)

Example 10 with ApplicationProperties

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

the class JMSMappingInboundTransformer method transform.

public MessageImpl transform(TransferFrame frame, DestinationFactory destinationFactory) throws AMQPException, JMSException {
    jmsTypeProp = getValue(PROP_JMS_TYPE, null);
    MessageImpl jmsMessage = null;
    try {
        AMQPMessage amqpMessage = null;
        if (frame.getMorePayloads() != null) {
            List morePayloads = frame.getMorePayloads();
            byte[][] b = new byte[morePayloads.size() + 1][];
            b[0] = frame.getPayload();
            for (int i = 0; i < morePayloads.size(); i++) b[i + 1] = (byte[]) morePayloads.get(i);
            amqpMessage = new AMQPMessage(b, frame.getPayloadLength());
        } else
            amqpMessage = new AMQPMessage(frame.getPayload());
        jmsMessage = messageFactory.create(amqpMessage);
        jmsMessage.setLongProperty(prefixVendor + Util.PROP_MESSAGE_FORMAT, frame.getMessageFormat().getValue());
        jmsMessage.setBooleanProperty(amqpNative, false);
        Header header = amqpMessage.getHeader();
        if (header != null)
            transformHeader(header, jmsMessage);
        DeliveryAnnotations deliveryAnnotations = amqpMessage.getDeliveryAnnotations();
        if (deliveryAnnotations != null)
            transformMap(deliveryAnnotations.getValue(), jmsMessage, prefixDA);
        MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
        if (messageAnnotations != null)
            transformMap(messageAnnotations.getValue(), jmsMessage, prefixMA);
        Properties properties = amqpMessage.getProperties();
        if (properties != null)
            transformProperties(properties, jmsMessage, destinationFactory);
        ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
        if (applicationProperties != null)
            transformApplicationProperties(applicationProperties, jmsMessage);
        Footer footer = amqpMessage.getFooter();
        if (footer != null)
            transformMap(footer.getValue(), jmsMessage, prefixFT);
    } catch (Exception e) {
        throw new AMQPException(e.toString());
    }
    jmsMessage.reset();
    return jmsMessage;
}
Also used : AMQPException(com.swiftmq.amqp.v100.client.AMQPException) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) JMSException(javax.jms.JMSException) List(java.util.List) MessageImpl(com.swiftmq.jms.MessageImpl)

Aggregations

AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)10 Map (java.util.Map)9 HashMap (java.util.HashMap)7 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)6 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)6 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)4 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)4 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)4 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)3 IOException (java.io.IOException)3 JMSException (javax.jms.JMSException)3 StreamException (com.rabbitmq.stream.StreamException)2 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)2 AMQPInt (com.swiftmq.amqp.v100.types.AMQPInt)2 MessageImpl (com.swiftmq.jms.MessageImpl)2 com.rabbitmq.stream.amqp (com.rabbitmq.stream.amqp)1 com.swiftmq.amqp.v100.generated.messaging.message_format (com.swiftmq.amqp.v100.generated.messaging.message_format)1 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)1 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)1 DataByteArrayOutputStream (com.swiftmq.tools.util.DataByteArrayOutputStream)1