Examples of AmqpValue


Examples of com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue

                Session session = connection.createSession(10, 10);
                Producer p = session.createProducer(queue, qos);
                for (int i = 0; i < nMsgs; i++) {
                    AMQPMessage msg = new AMQPMessage();
                    System.out.println("Sending " + i);
                    msg.setAmqpValue(new AmqpValue(new AMQPString(String.format(dataFormat, i))));
                    p.send(msg);
                }
                p.close();
                session.close();
            }
View Full Code Here

Examples of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue

    private static Section convertMessageBody(String mimeType, byte[] data)
    {
        if("text/plain".equals(mimeType) || "text/xml".equals(mimeType))
        {
            String text = new String(data);
            return new AmqpValue(text);
        }
        else if("jms/map-message".equals(mimeType))
        {
            TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(data));

            LinkedHashMap map = new LinkedHashMap();
            final int entries = reader.readIntImpl();
            for (int i = 0; i < entries; i++)
            {
                try
                {
                    String propName = reader.readStringImpl();
                    Object value = reader.readObject();

                    map.put(propName, value);
                }
                catch (EOFException e)
                {
                    throw new IllegalArgumentException(e);
                }
                catch (TypedBytesFormatException e)
                {
                    throw new IllegalArgumentException(e);
                }

            }

            return new AmqpValue(fixMapValues(map));

        }
        else if("amqp/map".equals(mimeType))
        {
            BBDecoder decoder = new BBDecoder();
            decoder.init(ByteBuffer.wrap(data));
            final Map<String,Object> map = decoder.readMap();

            return new AmqpValue(fixMapValues(map));

        }
        else if("amqp/list".equals(mimeType))
        {
            BBDecoder decoder = new BBDecoder();
            decoder.init(ByteBuffer.wrap(data));
            return new AmqpValue(fixListValues(decoder.readList()));
        }
        else if("jms/stream-message".equals(mimeType))
        {
            TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(data));

            List list = new ArrayList();
            while (reader.remaining() != 0)
            {
                try
                {
                    list.add(fixValue(reader.readObject()));
                }
                catch (TypedBytesFormatException e)
                {
                    throw new RuntimeException(e)// TODO - Implement
                }
                catch (EOFException e)
                {
                    throw new RuntimeException(e)// TODO - Implement
                }
            }
            return new AmqpValue(list);
        }
        else
        {
            return new Data(new Binary(data));
View Full Code Here

Examples of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue

            appPropMap.put(OPCODE, ANNOUNCE);
            appPropMap.put(VENDOR, vendor);
            appPropMap.put(ADDRESS,responseReceiver.getAddress());

            AmqpValue amqpValue = new AmqpValue(message);
            Section[] sections = { properties, appProperties, amqpValue};
            final Message message1 = new Message(Arrays.asList(sections));

            s.send(message1);

            Map<Object, Sender> sendingLinks = new HashMap<Object, Sender>();
            Map<Object, Receiver> receivingLinks = new HashMap<Object, Receiver>();


            boolean done = false;

            while(!done)
            {
                boolean wait = true;
                Message m = responseReceiver.receive(false);
                if(m != null)
                {
                    List<Section> payload = m.getPayload();
                    wait = false;
                    ApplicationProperties props = m.getApplicationProperties();
                    Map map = props.getValue();
                    String op = (String) map.get(OPCODE);
                    if("reset".equals(op))
                    {
                        for(Sender sender : sendingLinks.values())
                        {
                            try
                            {
                                sender.close();
                                Session session1 = sender.getSession();
                                session1.close();
                                session1.getConnection().close();
                            }
                            catch(Exception e)
                            {
                                e.printStackTrace();
                            }
                        }
                        for(Receiver receiver : receivingLinks.values())
                        {
                            try
                            {
                                receiver.close();
                                receiver.getSession().close();
                                receiver.getSession().getConnection().close();
                            }
                            catch(Exception e)
                            {
                                e.printStackTrace();
                            }
                        }
                        sendingLinks.clear();
                        receivingLinks.clear();
                    }
                    else if(CREATE_LINK.equals(op))
                    {
                        Object linkRef = map.get(LINK_REF);
                        String host = (String) map.get(HOST);
                        Object o = map.get(PORT);
                        int port = Integer.parseInt(String.valueOf(o));
                        String user = (String) map.get(SASL_USER);
                        String password = (String) map.get(SASL_PASSWORD);
                        String role = (String) map.get(ROLE);
                        String address = (String) map.get(ADDRESS);
                        System.err.println("Host: " + host + "\tPort: " + port + "\t user: " + user +"\t password: " + password);
                        try{


                            Connection conn2 = new Connection(host, port, user, password, host);
                            Session session2 = conn2.createSession();
                            if(sendingLinks.containsKey(linkRef))
                            {
                                try
                                {
                                    sendingLinks.remove(linkRef).close();
                                }
                                catch (Exception e)
                                {

                                }
                            }
                            if(receivingLinks.containsKey(linkRef))
                            {
                                try
                                {
                                    receivingLinks.remove(linkRef).close();
                                }
                                catch (Exception e)
                                {

                                }
                            }
                            if(SENDER.equals(role))
                            {

                                System.err.println("%%% Creating sender (" + linkRef + ")");
                                Sender sender = session2.createSender(address);
                                sendingLinks.put(linkRef, sender);
                            }
                            else
                            {

                                System.err.println("%%% Creating receiver (" + linkRef + ")");
                                Receiver receiver2 = session2.createReceiver(address);
                                receiver2.setCredit(UnsignedInteger.valueOf(getWindowSize()), true);

                                receivingLinks.put(linkRef, receiver2);
                            }
                        }
                        catch(Exception e)
                        {
                            e.printStackTrace();
                        }
                    }
                    else if(SEND_MESSAGE.equals(op))
                    {
                        Sender sender = sendingLinks.get(map.get(LINK_REF));
                        Properties m2props = new Properties();
                        Object messageId = map.get(MESSAGE_ID);
                        m2props.setMessageId(messageId);
                        Map m2propmap = new HashMap();
                        m2propmap.put(OPCODE, TEST);
                        m2propmap.put(VENDOR, vendor);
                        ApplicationProperties m2appProps = new ApplicationProperties(m2propmap);
                        Message m2 = new Message(Arrays.asList(m2props, m2appProps, new AmqpValue("AMQP-"+messageId)));
                        sender.send(m2);

                        Map m3propmap = new HashMap();
                        m3propmap.put(OPCODE, LOG);
                        m3propmap.put(ACTION, SENT);
                        m3propmap.put(MESSAGE_ID, messageId);
                        m3propmap.put(VENDOR, vendor);
                        m3propmap.put(MESSAGE_VENDOR, vendor);


                        Message m3 = new Message(Arrays.asList(new ApplicationProperties(m3propmap),
                                                               new AmqpValue("AMQP-"+messageId)));
                        s.send(m3);

                    }

                    responseReceiver.acknowledge(m);
                }
                else
                {
                    for(Map.Entry<Object, Receiver> entry : receivingLinks.entrySet())
                    {
                        m = entry.getValue().receive(false);
                        if(m != null)
                        {
                            wait = false;

                            System.err.println("%%% Received message from " + entry.getKey());

                            Properties mp = m.getProperties();
                            ApplicationProperties ap = m.getApplicationProperties();

                            Map m3propmap = new HashMap();
                            m3propmap.put(OPCODE, LOG);
                            m3propmap.put(ACTION, RECEIVED);
                            m3propmap.put(MESSAGE_ID, mp.getMessageId());
                            m3propmap.put(VENDOR, vendor);
                            m3propmap.put(MESSAGE_VENDOR, ap.getValue().get(VENDOR));

                            Message m3 = new Message(Arrays.asList(new ApplicationProperties(m3propmap),
                                                                   new AmqpValue("AMQP-"+mp.getMessageId())));
                            s.send(m3);

                            entry.getValue().acknowledge(m);
                        }
View Full Code Here

Examples of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue

                            }
                            bodySection = new Data(new Binary(bytes));
                        }
                        else
                        {
                            bodySection = new AmqpValue(message + " " + i);
                        }

                        Section[] sections = {properties, bodySection};
                        final Message message1 = new Message(Arrays.asList(sections));
View Full Code Here

Examples of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue

                {
                    Properties properties = new Properties();
                    properties.setMessageId(UnsignedLong.valueOf(i));
                    properties.setReplyTo(responseReceiver.getAddress());

                    AmqpValue amqpValue = new AmqpValue(message);
                    Section[] sections = { new Header() , properties, amqpValue};
                    final Message message1 = new Message(Arrays.asList(sections));

                    s.send(message1, txn);
View Full Code Here

Examples of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue

                {
                    Properties properties = new Properties();
                    properties.setMessageId(UnsignedLong.valueOf(i));
                    properties.setReplyTo(responseReceiver.getAddress());

                    AmqpValue amqpValue = new AmqpValue(message);
                    Section[] sections = { new Header() , properties, amqpValue};
                    final Message message1 = new Message(Arrays.asList(sections));

                    s.send(message1, txn);
View Full Code Here

Examples of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue

            appPropMap.put(OPCODE, ANNOUNCE);
            appPropMap.put(VENDOR, vendor);
            appPropMap.put(ADDRESS,responseReceiver.getAddress());

            AmqpValue amqpValue = new AmqpValue(message);
            Section[] sections = { properties, appProperties, amqpValue};
            final Message message1 = new Message(Arrays.asList(sections));

            try
            {
                s.send(message1);
            }
            catch (Exception e)
            {
                throw new RuntimeException(e);
            }

            Map<Object, Sender> sendingLinks = new HashMap<Object, Sender>();
            Map<Object, Receiver> receivingLinks = new HashMap<Object, Receiver>();


            boolean done = false;

            while(!done)
            {
                boolean wait = true;
                Message m = responseReceiver.receive(false);
                if(m != null)
                {
                    List<Section> payload = m.getPayload();
                    wait = false;
                    ApplicationProperties props = m.getApplicationProperties();
                    Map map = props.getValue();
                    String op = (String) map.get(OPCODE);
                    if("reset".equals(op))
                    {
                        for(Sender sender : sendingLinks.values())
                        {
                            try
                            {
                                sender.close();
                                Session session1 = sender.getSession();
                                session1.close();
                                session1.getConnection().close();
                            }
                            catch(Exception e)
                            {
                                e.printStackTrace();
                            }
                        }
                        for(Receiver receiver : receivingLinks.values())
                        {
                            try
                            {
                                receiver.close();
                                receiver.getSession().close();
                                receiver.getSession().getConnection().close();
                            }
                            catch(Exception e)
                            {
                                e.printStackTrace();
                            }
                        }
                        sendingLinks.clear();
                        receivingLinks.clear();
                    }
                    else if(CREATE_LINK.equals(op))
                    {
                        Object linkRef = map.get(LINK_REF);
                        String host = (String) map.get(HOST);
                        Object o = map.get(PORT);
                        int port = Integer.parseInt(String.valueOf(o));
                        String user = (String) map.get(SASL_USER);
                        String password = (String) map.get(SASL_PASSWORD);
                        String role = (String) map.get(ROLE);
                        String address = (String) map.get(ADDRESS);
                        System.err.println("Host: " + host + "\tPort: " + port + "\t user: " + user +"\t password: " + password);
                        try{


                            Connection conn2 = new Connection(host, port, user, password, host);
                            Session session2 = conn2.createSession();
                            if(sendingLinks.containsKey(linkRef))
                            {
                                try
                                {
                                    sendingLinks.remove(linkRef).close();
                                }
                                catch (Exception e)
                                {

                                }
                            }
                            if(receivingLinks.containsKey(linkRef))
                            {
                                try
                                {
                                    receivingLinks.remove(linkRef).close();
                                }
                                catch (Exception e)
                                {

                                }
                            }
                            if(SENDER.equals(role))
                            {

                                System.err.println("%%% Creating sender (" + linkRef + ")");
                                Sender sender = session2.createSender(address);
                                sendingLinks.put(linkRef, sender);
                            }
                            else
                            {

                                System.err.println("%%% Creating receiver (" + linkRef + ")");
                                Receiver receiver2 = session2.createReceiver(address);
                                receiver2.setCredit(UnsignedInteger.valueOf(getWindowSize()), true);

                                receivingLinks.put(linkRef, receiver2);
                            }
                        }
                        catch(Exception e)
                        {
                            e.printStackTrace();
                        }
                    }
                    else if(SEND_MESSAGE.equals(op))
                    {
                        Sender sender = sendingLinks.get(map.get(LINK_REF));
                        Properties m2props = new Properties();
                        Object messageId = map.get(MESSAGE_ID);
                        m2props.setMessageId(messageId);
                        Map m2propmap = new HashMap();
                        m2propmap.put(OPCODE, TEST);
                        m2propmap.put(VENDOR, vendor);
                        ApplicationProperties m2appProps = new ApplicationProperties(m2propmap);
                        Message m2 = new Message(Arrays.asList(m2props, m2appProps, new AmqpValue("AMQP-"+messageId)));
                        try
                        {
                            sender.send(m2);
                        }
                        catch (Exception e)
                        {
                            throw new RuntimeException(e);
                        }

                        Map m3propmap = new HashMap();
                        m3propmap.put(OPCODE, LOG);
                        m3propmap.put(ACTION, SENT);
                        m3propmap.put(MESSAGE_ID, messageId);
                        m3propmap.put(VENDOR, vendor);
                        m3propmap.put(MESSAGE_VENDOR, vendor);


                        Message m3 = new Message(Arrays.asList(new ApplicationProperties(m3propmap),
                                                               new AmqpValue("AMQP-"+messageId)));
                        try
                        {
                            s.send(m3);
                        }
                        catch (Exception e)
                        {
                            throw new RuntimeException(e);
                        }
                    }

                    responseReceiver.acknowledge(m);
                }
                else
                {
                    for(Map.Entry<Object, Receiver> entry : receivingLinks.entrySet())
                    {
                        m = entry.getValue().receive(false);
                        if(m != null)
                        {
                            wait = false;

                            System.err.println("%%% Received message from " + entry.getKey());

                            Properties mp = m.getProperties();
                            ApplicationProperties ap = m.getApplicationProperties();

                            Map m3propmap = new HashMap();
                            m3propmap.put(OPCODE, LOG);
                            m3propmap.put(ACTION, RECEIVED);
                            m3propmap.put(MESSAGE_ID, mp.getMessageId());
                            m3propmap.put(VENDOR, vendor);
                            m3propmap.put(MESSAGE_VENDOR, ap.getValue().get(VENDOR));

                            Message m3 = new Message(Arrays.asList(new ApplicationProperties(m3propmap),
                                                                   new AmqpValue("AMQP-"+mp.getMessageId())));
                            try
                            {
                                s.send(m3);
                            }
                            catch (Exception e)
View Full Code Here

Examples of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue

    private static Section convertMessageBody(String mimeType, byte[] data)
    {
        if("text/plain".equals(mimeType) || "text/xml".equals(mimeType))
        {
            String text = new String(data);
            return new AmqpValue(text);
        }
        else if("jms/map-message".equals(mimeType))
        {
            TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(data));

            LinkedHashMap map = new LinkedHashMap();
            final int entries = reader.readIntImpl();
            for (int i = 0; i < entries; i++)
            {
                try
                {
                    String propName = reader.readStringImpl();
                    Object value = reader.readObject();
                    map.put(propName, value);
                }
                catch (EOFException e)
                {
                    throw new IllegalArgumentException(e);
                }
                catch (TypedBytesFormatException e)
                {
                    throw new IllegalArgumentException(e);
                }

            }

            return new AmqpValue(map);

        }
        else if("amqp/map".equals(mimeType))
        {
            BBDecoder decoder = new BBDecoder();
            decoder.init(ByteBuffer.wrap(data));
            return new AmqpValue(decoder.readMap());

        }
        else if("amqp/list".equals(mimeType))
        {
            BBDecoder decoder = new BBDecoder();
            decoder.init(ByteBuffer.wrap(data));
            return new AmqpValue(decoder.readList());
        }
        else if("jms/stream-message".equals(mimeType))
        {
            TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(data));

            List list = new ArrayList();
            while (reader.remaining() != 0)
            {
                try
                {
                    list.add(reader.readObject());
                }
                catch (TypedBytesFormatException e)
                {
                    throw new RuntimeException(e)// TODO - Implement
                }
                catch (EOFException e)
                {
                    throw new RuntimeException(e)// TODO - Implement
                }
            }
            return new AmqpValue(list);
        }
        else
        {
            return new Data(new Binary(data));
View Full Code Here

Examples of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue

    private static Section convertMessageBody(String mimeType, byte[] data)
    {
        if("text/plain".equals(mimeType) || "text/xml".equals(mimeType))
        {
            String text = new String(data);
            return new AmqpValue(text);
        }
        else if("jms/map-message".equals(mimeType))
        {
            TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(data));

            LinkedHashMap map = new LinkedHashMap();
            final int entries = reader.readIntImpl();
            for (int i = 0; i < entries; i++)
            {
                try
                {
                    String propName = reader.readStringImpl();
                    Object value = reader.readObject();
                    map.put(propName, value);
                }
                catch (EOFException e)
                {
                    throw new IllegalArgumentException(e);
                }
                catch (TypedBytesFormatException e)
                {
                    throw new IllegalArgumentException(e);
                }

            }

            return new AmqpValue(map);

        }
        else if("amqp/map".equals(mimeType))
        {
            BBDecoder decoder = new BBDecoder();
            decoder.init(ByteBuffer.wrap(data));
            return new AmqpValue(decoder.readMap());

        }
        else if("amqp/list".equals(mimeType))
        {
            BBDecoder decoder = new BBDecoder();
            decoder.init(ByteBuffer.wrap(data));
            return new AmqpValue(decoder.readList());
        }
        else if("jms/stream-message".equals(mimeType))
        {
            TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(data));

            List list = new ArrayList();
            while (reader.remaining() != 0)
            {
                try
                {
                    list.add(reader.readObject());
                }
                catch (TypedBytesFormatException e)
                {
                    throw new RuntimeException(e)// TODO - Implement
                }
                catch (EOFException e)
                {
                    throw new RuntimeException(e)// TODO - Implement
                }
            }
            return new AmqpValue(list);
        }
        else
        {
            return new Data(new Binary(data));
View Full Code Here

Examples of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue

        this(Collections.singletonList(section));
    }

    public Message(String message)
    {
        this(new AmqpValue(message));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.