Package org.apache.qpid.transport

Examples of org.apache.qpid.transport.MessageProperties


    }

    public void messageTransfer(String destination, Message msg, short acceptMode, short acquireMode) throws IOException
    {
        DeliveryProperties dp = msg.getDeliveryProperties();
        MessageProperties mp = msg.getMessageProperties();
        ByteBuffer  body = msg.readData();
        int size = body.remaining();
        super.messageTransfer
            (destination, MessageAcceptMode.get(acceptMode),
             MessageAcquireMode.get(acquireMode),
View Full Code Here


        ssn.messageSubscribe("queue1", "myDest", (short)0, (short)0,createAdapter(), null);

        // queue
        ssn.messageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
                            new Header(new DeliveryProperties().setRoutingKey("queue1"),
                                       new MessageProperties().setMessageId(UUID.randomUUID())),
                            ByteBuffer.wrap("this is the data".getBytes()));

        //reject
        ssn.messageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
                            new Header(new DeliveryProperties().setRoutingKey("stocks")),
                            ByteBuffer.wrap("this should be rejected".getBytes()));
        ssn.sync();

        // topic subs
        ssn.messageSubscribe("topic1", "myDest2", (short)0, (short)0,createAdapter(), null);
        ssn.messageSubscribe("topic2", "myDest3", (short)0, (short)0,createAdapter(), null);
        ssn.messageSubscribe("topic3", "myDest4", (short)0, (short)0,createAdapter(), null);
        ssn.sync();

        ssn.queueDeclare("topic1", null, null);
        ssn.exchangeBind("topic1", "amq.topic", "stock.*",null);
        ssn.queueDeclare("topic2", null, null);
        ssn.exchangeBind("topic2", "amq.topic", "stock.us.*",null);
        ssn.queueDeclare("topic3", null, null);
        ssn.exchangeBind("topic3", "amq.topic", "stock.us.rh",null);
        ssn.sync();

        // topic
        ssn.messageTransfer("amq.topic", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
                            new Header(new DeliveryProperties().setRoutingKey("stock.us.ibm"),
                                       new MessageProperties().setMessageId(UUID.randomUUID())),
                            ByteBuffer.wrap("Topic message".getBytes()));
    }
View Full Code Here

    private String[] getMessageTransferMessageHeaderProps(MessageTransferMessage msg)
    {
        List<String> list = new ArrayList<String>();

        AMQMessageHeader header = msg.getMessageHeader();
        MessageProperties msgProps = msg.getHeader().get(MessageProperties.class);

        String appID = null;
        String userID = null;

        if(msgProps != null)
        {
            appID = msgProps.getAppId() == null ? "null" : new String(msgProps.getAppId());
            userID = msgProps.getUserId() == null ? "null" : new String(msgProps.getUserId());
        }

        list.add("reply-to = " + header.getReplyTo());
        list.add("propertyFlags = "); //TODO
        list.add("ApplicationID = " + appID);
View Full Code Here


        MessageTransfer xfr;

        DeliveryProperties deliveryProps;
        MessageProperties messageProps = null;

        if(serverMsg instanceof MessageTransferMessage)
        {

            MessageTransferMessage msg = (MessageTransferMessage) serverMsg;


            Struct[] headers;
            if(msg.getHeader() == null)
            {
                headers = EMPTY_STRUCT_ARRAY;
            }
            else
            {
                headers = msg.getHeader().getStructs();
            }

            ArrayList<Struct> newHeaders = new ArrayList<Struct>(headers.length);
            DeliveryProperties origDeliveryProps = null;
            for(Struct header : headers)
            {
                if(header instanceof DeliveryProperties)
                {
                    origDeliveryProps = (DeliveryProperties) header;
                }
                else
                {
                    if(header instanceof MessageProperties)
                    {
                        messageProps = (MessageProperties) header;
                    }
                    newHeaders.add(header);
                }
            }

            deliveryProps = new DeliveryProperties();
            if(origDeliveryProps != null)
            {
                if(origDeliveryProps.hasDeliveryMode())
                {
                    deliveryProps.setDeliveryMode(origDeliveryProps.getDeliveryMode());
                }
                if(origDeliveryProps.hasExchange())
                {
                    deliveryProps.setExchange(origDeliveryProps.getExchange());
                }
                if(origDeliveryProps.hasExpiration())
                {
                    deliveryProps.setExpiration(origDeliveryProps.getExpiration());
                }
                if(origDeliveryProps.hasPriority())
                {
                    deliveryProps.setPriority(origDeliveryProps.getPriority());
                }
                if(origDeliveryProps.hasRoutingKey())
                {
                    deliveryProps.setRoutingKey(origDeliveryProps.getRoutingKey());
                }
                if(origDeliveryProps.hasTimestamp())
                {
                    deliveryProps.setTimestamp(origDeliveryProps.getTimestamp());
                }


            }

            deliveryProps.setRedelivered(entry.isRedelivered());

            newHeaders.add(deliveryProps);

            if(_trace != null && messageProps == null)
            {
                messageProps = new MessageProperties();
                newHeaders.add(messageProps);
            }

            Header header = new Header(newHeaders);

            xfr = new MessageTransfer(_destination,_acceptMode,_acquireMode,header,msg.getBody());
        }
        else if(serverMsg instanceof AMQMessage)
        {
            AMQMessage message_0_8 = (AMQMessage) serverMsg;
            deliveryProps = new DeliveryProperties();
            messageProps = new MessageProperties();

            int size = (int) message_0_8.getSize();
            ByteBuffer body = ByteBuffer.allocate(size);
            message_0_8.getContent(body, 0);
            body.flip();

            Struct[] headers = new Struct[] { deliveryProps, messageProps };

            BasicContentHeaderProperties properties =
                    (BasicContentHeaderProperties) message_0_8.getContentHeaderBody().getProperties();
            final AMQShortString exchange = message_0_8.getMessagePublishInfo().getExchange();
            if(exchange != null)
            {
                deliveryProps.setExchange(exchange.toString());
            }
            deliveryProps.setExpiration(message_0_8.getExpiration());
            deliveryProps.setImmediate(message_0_8.isImmediate());
            deliveryProps.setPriority(MessageDeliveryPriority.get(properties.getPriority()));
            deliveryProps.setRedelivered(entry.isRedelivered());
            deliveryProps.setRoutingKey(message_0_8.getRoutingKey());
            deliveryProps.setTimestamp(properties.getTimestamp());

            messageProps.setContentEncoding(properties.getEncodingAsString());
            messageProps.setContentLength(size);
            if(properties.getAppId() != null)
            {
                messageProps.setAppId(properties.getAppId().getBytes());
            }
            messageProps.setContentType(properties.getContentTypeAsString());
            if(properties.getCorrelationId() != null)
            {
                messageProps.setCorrelationId(properties.getCorrelationId().getBytes());
            }

            // TODO - ReplyTo

            if(properties.getUserId() != null)
            {
                messageProps.setUserId(properties.getUserId().getBytes());
            }

            FieldTable fieldTable = properties.getHeaders();

            final Map<String, Object> appHeaders = FieldTable.convertToMap(fieldTable);


            messageProps.setApplicationHeaders(appHeaders);

            Header header = new Header(headers);
            xfr = new MessageTransfer(_destination,_acceptMode,_acquireMode,header, body);
        }
        else
        {

            deliveryProps = new DeliveryProperties();
            messageProps = new MessageProperties();

            int size = (int) serverMsg.getSize();
            ByteBuffer body = ByteBuffer.allocate(size);
            serverMsg.getContent(body, 0);
            body.flip();

            Struct[] headers = new Struct[] { deliveryProps, messageProps };


            deliveryProps.setExpiration(serverMsg.getExpiration());
            deliveryProps.setImmediate(serverMsg.isImmediate());
            deliveryProps.setPriority(MessageDeliveryPriority.get(serverMsg.getMessageHeader().getPriority()));
            deliveryProps.setRedelivered(entry.isRedelivered());
            deliveryProps.setRoutingKey(serverMsg.getRoutingKey());
            deliveryProps.setTimestamp(serverMsg.getMessageHeader().getTimestamp());

            messageProps.setContentEncoding(serverMsg.getMessageHeader().getEncoding());
            messageProps.setContentLength(size);
            messageProps.setContentType(serverMsg.getMessageHeader().getMimeType());
            if(serverMsg.getMessageHeader().getCorrelationId() != null)
            {
                messageProps.setCorrelationId(serverMsg.getMessageHeader().getCorrelationId().getBytes());
            }


            // TODO - ReplyTo


            final Map<String, Object> appHeaders = new HashMap<String, Object>();

            /*properties.getHeaders().processOverElements(
                    new FieldTable.FieldTableElementProcessor()
                    {

                        public boolean processElement(String propertyName, AMQTypedValue value)
                        {
                            Object val = value.getValue();
                            if(val instanceof AMQShortString)
                            {
                                val = val.toString();
                            }
                            appHeaders.put(propertyName, val);
                            return true;
                        }

                        public Object getResult()
                        {
                            return appHeaders;
                        }
                    });


            messageProps.setApplicationHeaders(appHeaders);
*/
            Header header = new Header(headers);
            xfr = new MessageTransfer(_destination,_acceptMode,_acquireMode,header, body);
        }

        boolean excludeDueToFederation = false;

        if(_trace != null)
        {
            if(!messageProps.hasApplicationHeaders())
            {
                messageProps.setApplicationHeaders(new HashMap<String,Object>());
            }
            Map<String,Object> appHeaders = messageProps.getApplicationHeaders();
            String trace = (String) appHeaders.get("x-qpid.trace");
            if(trace == null)
            {
                trace = _trace;
            }
View Full Code Here

    {
        BasicContentHeaderProperties props = new BasicContentHeaderProperties();

        Header header = messageTransferMessage.getHeader();
        DeliveryProperties deliveryProps = header.get(DeliveryProperties.class);
        MessageProperties messageProps = header.get(MessageProperties.class);

        if(deliveryProps != null)
        {
            if(deliveryProps.hasDeliveryMode())
            {
                props.setDeliveryMode((byte)(deliveryProps.getDeliveryMode() == MessageDeliveryMode.PERSISTENT ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT));
            }
            if(deliveryProps.hasExpiration())
            {
                props.setExpiration(deliveryProps.getExpiration());
            }
            if(deliveryProps.hasPriority())
            {
                props.setPriority((byte)deliveryProps.getPriority().getValue());
            }
            if(deliveryProps.hasTimestamp())
            {
                props.setTimestamp(deliveryProps.getTimestamp());
            }
        }
        if(messageProps != null)
        {
            if(messageProps.hasAppId())
            {
                props.setAppId(new AMQShortString(messageProps.getAppId()));
            }
            if(messageProps.hasContentType())
            {
                props.setContentType(messageProps.getContentType());
            }
            if(messageProps.hasCorrelationId())
            {
                props.setCorrelationId(new AMQShortString(messageProps.getCorrelationId()));
            }
            if(messageProps.hasContentEncoding())
            {
                props.setEncoding(messageProps.getContentEncoding());
            }
            if(messageProps.hasMessageId())
            {
                props.setMessageId(messageProps.getMessageId().toString());
            }

            // TODO Reply-to

            if(messageProps.hasUserId())
            {
                props.setUserId(new AMQShortString(messageProps.getUserId()));
            }

            if(messageProps.hasApplicationHeaders())
            {
                Map<String, Object> appHeaders = messageProps.getApplicationHeaders();
                FieldTable ft = new FieldTable();
                for(Map.Entry<String, Object> entry : appHeaders.entrySet())
                {
                    try
                    {
View Full Code Here

    }

    public ByteBufferMessage()
    {
        _currentDeliveryProps = new DeliveryProperties();
        _currentMessageProps = new MessageProperties();
    }
View Full Code Here

        message.prepareForSending();

        AMQMessageDelegate_0_10 delegate = (AMQMessageDelegate_0_10) message.getDelegate();

        DeliveryProperties deliveryProp = delegate.getDeliveryProperties();
        MessageProperties messageProps = delegate.getMessageProperties();

        // On the receiving side, this will be read in to the JMSXUserID as well.
        messageProps.setUserId(userIDBytes);
               
        if (messageId != null)
        {
            messageProps.setMessageId(messageId);
        }
        else if (messageProps.hasMessageId())
        {
            messageProps.clearMessageId();
        }

        long currentTime = 0;
        if (timeToLive > 0 || !_disableTimestamps)
        {
            currentTime = System.currentTimeMillis();
        }       
       
        if (timeToLive > 0)
        {
            deliveryProp.setTtl(timeToLive);
            message.setJMSExpiration(currentTime + timeToLive);
        }
       
        if (!_disableTimestamps)
        {
           
            deliveryProp.setTimestamp(currentTime);           
            message.setJMSTimestamp(currentTime);
        }

        if (!deliveryProp.hasDeliveryMode() || deliveryProp.getDeliveryMode().getValue() != deliveryMode)
        {
            MessageDeliveryMode mode;
            switch (deliveryMode)
            {
            case DeliveryMode.PERSISTENT:
                mode = MessageDeliveryMode.PERSISTENT;
                break;
            case DeliveryMode.NON_PERSISTENT:
                mode = MessageDeliveryMode.NON_PERSISTENT;
                break;
            default:
                throw new IllegalArgumentException("illegal delivery mode: " + deliveryMode);
            }
            deliveryProp.setDeliveryMode(mode);
            message.setJMSDeliveryMode(deliveryMode);
        }
        if (!deliveryProp.hasPriority() || deliveryProp.getPriority().getValue() != priority)
        {
            deliveryProp.setPriority(MessageDeliveryPriority.get((short) priority));
            message.setJMSPriority(priority);
        }
        String exchangeName = destination.getExchangeName() == null ? "" : destination.getExchangeName().toString();
        if ( deliveryProp.getExchange() == null || ! deliveryProp.getExchange().equals(exchangeName))
        {
            deliveryProp.setExchange(exchangeName);
        }
        String routingKey = destination.getRoutingKey().toString();
        if (deliveryProp.getRoutingKey() == null || ! deliveryProp.getRoutingKey().equals(routingKey))
        {
            deliveryProp.setRoutingKey(routingKey);
        }
       
        if (destination.getDestSyntax() == AMQDestination.DestSyntax.ADDR &&
           (destination.getSubject() != null ||
              (messageProps.getApplicationHeaders() != null && messageProps.getApplicationHeaders().get(QpidMessageProperties.QPID_SUBJECT) != null))
           )
        {
            Map<String,Object> appProps = messageProps.getApplicationHeaders();
            if (appProps == null)
            {
                appProps = new HashMap<String,Object>();
                messageProps.setApplicationHeaders(appProps);         
            }
           
            if (appProps.get(QpidMessageProperties.QPID_SUBJECT) == null)
            {
                // use default subject in address string
                appProps.put(QpidMessageProperties.QPID_SUBJECT,destination.getSubject());
            }
                   
            if (destination.getAddressType() == AMQDestination.TOPIC_TYPE)
            {
                deliveryProp.setRoutingKey((String)
                        messageProps.getApplicationHeaders().get(QpidMessageProperties.QPID_SUBJECT));               
            }
        }

        ByteBuffer data = message.getData();
        messageProps.setContentLength(data.remaining());

        // send the message
        try
        {
            org.apache.qpid.transport.Session ssn = (org.apache.qpid.transport.Session)
View Full Code Here

        ssn.invoke(new QueueDeclare().queue("test-queue").durable(false));
        ssn.invoke(new QueueDeclare().queue("echo-queue").durable(false));
        ssn.invoke(new ExchangeBind().exchange("amq.direct").queue("test-queue").bindingKey("test-queue"));
        ssn.invoke(new ExchangeBind().exchange("amq.direct").queue("echo-queue").bindingKey("echo-queue"));

        MessageProperties cached_mp = new MessageProperties();
        DeliveryProperties cached_dp = new DeliveryProperties();
        cached_dp.setRoutingKey("test-queue");
        cached_dp.setDeliveryMode
            (opts.persistent ? MessageDeliveryMode.PERSISTENT : MessageDeliveryMode.NON_PERSISTENT);

        int size = opts.size;
        ByteBuffer body = ByteBuffer.allocate(size);
        for (int i = 0; i < size; i++)
        {
            body.put((byte) i);
        }
        body.flip();

        ssn.invoke(new MessageSubscribe()
                   .queue("echo-queue")
                   .destination("echo-queue")
                   .acceptMode(MessageAcceptMode.NONE)
                   .acquireMode(MessageAcquireMode.PRE_ACQUIRED));
        ssn.messageSetFlowMode("echo-queue", MessageFlowMode.WINDOW);
        ssn.messageFlow("echo-queue", MessageCreditUnit.MESSAGE, 0xFFFFFFFF);
        ssn.messageFlow("echo-queue", MessageCreditUnit.BYTE, 0xFFFFFFFF);

        UUIDGen gen = UUIDs.newGenerator();

        long count = 0;
        long lastTime = 0;
        long start = System.currentTimeMillis();
        while (opts.count == 0 || count < opts.count)
        {
            if (opts.window > 0 && (count % opts.window) == 0 && count > 0)
            {
                synchronized (echos)
                {
                    while (echos[0] < (count/opts.window))
                    {
                        echos.wait();
                    }
                }
            }

            if (opts.sample > 0 && (count % opts.sample) == 0)
            {
                long time = System.currentTimeMillis();
                sample(opts, Column.LEFT, "NP", count, start, time, lastTime);
                lastTime = time;
            }

            MessageProperties mp;
            DeliveryProperties dp;
            if (opts.message_cache)
            {
                mp = cached_mp;
                dp = cached_dp;
            }
            else
            {
                mp = new MessageProperties();
                dp = new DeliveryProperties();
                dp.setRoutingKey("test-queue");
                dp.setDeliveryMode
                    (opts.persistent ? MessageDeliveryMode.PERSISTENT : MessageDeliveryMode.NON_PERSISTENT);

            }

            if (opts.message_id)
            {
                mp.setMessageId(gen.generate());
            }

            if (opts.timestamp)
            {
                dp.setTimestamp(System.currentTimeMillis());
View Full Code Here

    {
        final DeliveryProperties dp = new DeliveryProperties();
        final byte[] echo = new byte[0];
        dp.setRoutingKey("echo-queue");
        dp.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
        final MessageProperties mp = new MessageProperties();
        final Object done = new Object();
        org.apache.qpid.transport.Connection conn = getConnection(opts);
        org.apache.qpid.transport.Session ssn = conn.createSession();
        ssn.setSessionListener(new NativeListener()
        {
View Full Code Here

        message.prepareForSending();

        AMQMessageDelegate_0_10 delegate = (AMQMessageDelegate_0_10) message.getDelegate();

        DeliveryProperties deliveryProp = delegate.getDeliveryProperties();
        MessageProperties messageProps = delegate.getMessageProperties();

        // On the receiving side, this will be read in to the JMSXUserID as well.
        messageProps.setUserId(userIDBytes);
               
        if (messageId != null)
        {
            messageProps.setMessageId(messageId);
        }
        else if (messageProps.hasMessageId())
        {
            messageProps.clearMessageId();
        }

        long currentTime = 0;
        if (timeToLive > 0 || !isDisableTimestamps())
        {
            currentTime = System.currentTimeMillis();
        }       
       
        if (timeToLive > 0)
        {
            deliveryProp.setTtl(timeToLive);
            message.setJMSExpiration(currentTime + timeToLive);
        }
       
        if (!isDisableTimestamps())
        {
           
            deliveryProp.setTimestamp(currentTime);           
            message.setJMSTimestamp(currentTime);
        }

        if (!deliveryProp.hasDeliveryMode() || deliveryProp.getDeliveryMode().getValue() != deliveryMode)
        {
            MessageDeliveryMode mode;
            switch (deliveryMode)
            {
            case DeliveryMode.PERSISTENT:
                mode = MessageDeliveryMode.PERSISTENT;
                break;
            case DeliveryMode.NON_PERSISTENT:
                mode = MessageDeliveryMode.NON_PERSISTENT;
                break;
            default:
                throw new IllegalArgumentException("illegal delivery mode: " + deliveryMode);
            }
            deliveryProp.setDeliveryMode(mode);
            message.setJMSDeliveryMode(deliveryMode);
        }
        if (!deliveryProp.hasPriority() || deliveryProp.getPriority().getValue() != priority)
        {
            deliveryProp.setPriority(MessageDeliveryPriority.get((short) priority));
            message.setJMSPriority(priority);
        }
        String exchangeName = destination.getExchangeName() == null ? "" : destination.getExchangeName().toString();
        if ( deliveryProp.getExchange() == null || ! deliveryProp.getExchange().equals(exchangeName))
        {
            deliveryProp.setExchange(exchangeName);
        }
        String routingKey = destination.getRoutingKey().toString();
        if (deliveryProp.getRoutingKey() == null || ! deliveryProp.getRoutingKey().equals(routingKey))
        {
            deliveryProp.setRoutingKey(routingKey);
        }
       
        if (destination.getDestSyntax() == AMQDestination.DestSyntax.ADDR &&
           (destination.getSubject() != null ||
              (messageProps.getApplicationHeaders() != null && messageProps.getApplicationHeaders().get(QpidMessageProperties.QPID_SUBJECT) != null))
           )
        {
            Map<String,Object> appProps = messageProps.getApplicationHeaders();
            if (appProps == null)
            {
                appProps = new HashMap<String,Object>();
                messageProps.setApplicationHeaders(appProps);         
            }
           
            if (appProps.get(QpidMessageProperties.QPID_SUBJECT) == null)
            {
                // use default subject in address string
                appProps.put(QpidMessageProperties.QPID_SUBJECT,destination.getSubject());
            }
                   
            if (destination.getAddressType() == AMQDestination.TOPIC_TYPE)
            {
                deliveryProp.setRoutingKey((String)
                        messageProps.getApplicationHeaders().get(QpidMessageProperties.QPID_SUBJECT));               
            }
        }

        ByteBuffer data = message.getData();
        messageProps.setContentLength(data.remaining());

        // send the message
        try
        {
            org.apache.qpid.transport.Session ssn = (org.apache.qpid.transport.Session)
View Full Code Here

TOP

Related Classes of org.apache.qpid.transport.MessageProperties

Copyright © 2018 www.massapicom. 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.