Package org.apache.activemq.command

Examples of org.apache.activemq.command.Message


            if (isSendAdvisoryIfNoConsumers()) {
                // allow messages with no consumers to be dispatched to a dead
                // letter queue
                if (destination.isQueue() || !AdvisorySupport.isAdvisoryTopic(destination)) {

                    Message message = msg.copy();
                    // The original destination and transaction id do not get
                    // filled when the message is first sent,
                    // it is only populated if the message is routed to another
                    // destination like the DLQ
                    if (message.getOriginalDestination() != null) {
                        message.setOriginalDestination(message.getDestination());
                    }
                    if (message.getOriginalTransactionId() != null) {
                        message.setOriginalTransactionId(message.getTransactionId());
                    }

                    ActiveMQTopic advisoryTopic;
                    if (destination.isQueue()) {
                        advisoryTopic = AdvisorySupport.getNoQueueConsumersAdvisoryTopic(destination);
                    } else {
                        advisoryTopic = AdvisorySupport.getNoTopicConsumersAdvisoryTopic(destination);
                    }
                    message.setDestination(advisoryTopic);
                    message.setTransactionId(null);

                    // Disable flow control for this since since we don't want
                    // to block.
                    boolean originalFlowControl = context.isProducerFlowControl();
                    try {
View Full Code Here


        return result;
    }

    @Override
    public void preProcessDispatch(MessageDispatch messageDispatch) {
        Message message = messageDispatch.getMessage();
        if (message != null) {
            long endTime = System.currentTimeMillis();
            message.setBrokerOutTime(endTime);
            if (getBrokerService().isEnableStatistics()) {
                long totalTime = endTime - message.getBrokerInTime();
                message.getRegionDestination().getDestinationStatistics().getProcessTime().addTime(totalTime);
            }
        }
    }
View Full Code Here

    public boolean isExpired(MessageReference messageReference) {
        boolean expired = false;
        if (messageReference.isExpired()) {
            try {
                // prevent duplicate expiry processing
                Message message = messageReference.getMessage();
                synchronized (message) {
                    expired = stampAsExpired(message);
                }
            } catch (IOException e) {
                LOG.warn("unexpected exception on message expiry determination for: " + messageReference, e);
View Full Code Here

    @Override
    public void sendToDeadLetterQueue(ConnectionContext context,
          MessageReference node){
    try{
      if(node!=null){
        Message message=node.getMessage();
        if(message!=null && node.getRegionDestination()!=null){
          DeadLetterStrategy deadLetterStrategy=node
                  .getRegionDestination().getDeadLetterStrategy();
          if(deadLetterStrategy!=null){
            if(deadLetterStrategy.isSendToDeadLetterQueue(message)){
                // message may be inflight to other subscriptions so do not modify
                message = message.copy();
                stampAsExpired(message);
                message.setExpiration(0);
                if(!message.isPersistent()){
                  message.setPersistent(true);
                  message.setProperty("originalDeliveryMode",
                        "NON_PERSISTENT");
              }
              // The original destination and transaction id do
              // not get filled when the message is first sent,
              // it is only populated if the message is routed to
              // another destination like the DLQ
              ActiveMQDestination deadLetterDestination=deadLetterStrategy
                      .getDeadLetterQueueFor(message
                              .getDestination());
              if (context.getBroker()==null) {
                context.setBroker(getRoot());
              }
              BrokerSupport.resendNoCopy(context,message,
                      deadLetterDestination);
            }
          } else {
              if (LOG.isDebugEnabled()) {
                  LOG.debug("Dead Letter message with no DLQ strategy in place, message id: "
                                    + message.getMessageId() + ", destination: " + message.getDestination());
              }
          }
        }
      }
    }catch(Exception e){
View Full Code Here

    public QueueView(ManagedRegionBroker broker, Queue destination) {
        super(broker, destination);
    }

    public CompositeData getMessage(String messageId) throws OpenDataException {
        Message rc = ((Queue)destination).getMessage(messageId);
        if (rc == null) {
            return null;
        }
        return OpenTypeSupport.convert(rc);
    }
View Full Code Here

    /**
     * Moves a message back to its original destination
     */
    public boolean retryMessage(String messageId) throws Exception {
        Queue queue = (Queue) destination;
        Message rc = queue.getMessage(messageId);
        if (rc != null) {
            rc = rc.copy();
            rc.getMessage().setRedeliveryCounter(0);
            ActiveMQDestination originalDestination = rc.getOriginalDestination();
            if (originalDestination != null) {
                ConnectionContext context = BrokerSupport.getConnectionContext(broker.getContextBroker());
                return queue.moveMessageTo(context, rc, originalDestination);
            }
            else {
View Full Code Here

            sequenceGenerator.setLastSequenceId(seq);
            long brokerSeq = 0;
            if (seq != 0) {
                byte[] msg = getAdapter().doGetMessageById(c, seq);
                if (msg != null) {
                    Message last = (Message)wireFormat.unmarshal(new ByteSequence(msg));
                    brokerSeq = last.getMessageId().getBrokerSequenceId();
                } else {
                   LOG.warn("Broker sequence id wasn't recovered properly, possible duplicates!");
                }
            }
            return brokerSeq;
View Full Code Here

    }

    @Override
    public synchronized void addMessageLast(MessageReference node) throws Exception {
        if (node != null) {
            Message msg = node.getMessage();
            if (isStarted()) {
                if (!msg.isPersistent()) {
                    nonPersistent.addMessageLast(node);
                }
            }
            if (msg.isPersistent()) {
                Destination dest = msg.getRegionDestination();
                TopicStorePrefetch tsp = topics.get(dest);
                if (tsp != null) {
                    tsp.addMessageLast(node);
                }
            }
View Full Code Here

            }
          }

        } else if ((cronValue != null || periodValue != null || delayValue != null) && jobId == null) {
            //clear transaction context
            Message msg = messageSend.copy();
            msg.setTransactionId(null);
            org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(msg);
            if (cronValue != null) {
                cronEntry = cronValue.toString();
            }
            if (periodValue != null) {
              period = (Long) TypeConversionSupport.convert(periodValue, Long.class);
            }
            if (delayValue != null) {
                delay = (Long) TypeConversionSupport.convert(delayValue, Long.class);
            }
            Object repeatValue = msg.getProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT);
            if (repeatValue != null) {
                repeat = (Integer) TypeConversionSupport.convert(repeatValue, Integer.class);
            }
            getInternalScheduler().schedule(msg.getMessageId().toString(),
                    new ByteSequence(packet.data, packet.offset, packet.length),cronEntry, delay, period, repeat);

        } else {
            super.send(producerExchange, messageSend);
        }
View Full Code Here

    public void scheduledJob(String id, ByteSequence job) {
        org.apache.activemq.util.ByteSequence packet = new org.apache.activemq.util.ByteSequence(job.getData(), job
                .getOffset(), job.getLength());
        try {
            Message messageSend = (Message) this.wireFormat.unmarshal(packet);
            messageSend.setOriginalTransactionId(null);
            Object repeatValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT);
            Object cronValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT);
            String cronStr = cronValue != null ? cronValue.toString() : null;
            int repeat = 0;
            if (repeatValue != null) {
                repeat = (Integer) TypeConversionSupport.convert(repeatValue, Integer.class);
            }

            if (repeat != 0 || cronStr != null && cronStr.length() > 0) {
                // create a unique id - the original message could be sent
                // lots of times
                messageSend.setMessageId(
                    new MessageId(this.producerId, this.messageIdGenerator.getNextSequenceId()));
            }

            // Add the jobId as a property
            messageSend.setProperty("scheduledJobId", id);

            // if this goes across a network - we don't want it rescheduled
            messageSend.removeProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD);
            messageSend.removeProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY);
            messageSend.removeProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT);
            messageSend.removeProperty(ScheduledMessage.AMQ_SCHEDULED_CRON);

            final ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
            producerExchange.setConnectionContext(context);
            producerExchange.setMutable(true);
            producerExchange.setProducerState(new ProducerState(new ProducerInfo()));
View Full Code Here

TOP

Related Classes of org.apache.activemq.command.Message

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.