activemq消息分发MessageDispatch



1,ActiveMQConnection下的接受方法


    public void onCommand(final Object o) {
        final Command command = (Command)o;
        if (!closed.get() && command != null) {
            try {
                command.visit(new CommandVisitorAdapter() {
                    @Override
                    public Response processMessageDispatch(MessageDispatch md) throws Exception {
                        waitForTransportInterruptionProcessingToComplete();
                        ActiveMQDispatcher dispatcher = dispatchers.get(md.getConsumerId());
                        if (dispatcher != null) {
                            // Copy in case a embedded broker is dispatching via
                            // vm://
                            // md.getMessage() == null to signal end of queue
                            // browse.
                            Message msg = md.getMessage();
                            if (msg != null) {
                                msg = msg.copy();
                                msg.setReadOnlyBody(true);
                                msg.setReadOnlyProperties(true);
                                msg.setRedeliveryCounter(md.getRedeliveryCounter());
                                msg.setConnection(ActiveMQConnection.this);
                                md.setMessage(msg);
                            }
                            dispatcher.dispatch(md);
                        }
                        return null;
                    }
}




2,MessageDispatch 类实例
MessageDispatch {commandId = 4, responseRequired = false, consumerId = ID:shijiangyong-3522-1411886444218-1:1:-1:1, destination = topic://ActiveMQ.Advisory.Queue, message = ActiveMQMessage {commandId = 0, responseRequired = false, messageId = ID:shijiangyong-1615-1411873155375-0:0:0:0:1, originalDestination = null, originalTransactionId = null, producerId = ID:shijiangyong-1615-1411873155375-0:0:0:0, destination = topic://ActiveMQ.Advisory.Queue, transactionId = null, expiration = 0, timestamp = 0, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null, replyTo = null, persistent = false, type = Advisory, priority = 0, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = org.apache.activemq.util.ByteSequence@9b5027, dataStructure = DestinationInfo {commandId = 0, responseRequired = false, connectionId = null, destination = queue://resendqueue3, operationType = 0, timeout = 0, brokerPath = null}, redeliveryCounter = 0, size = 0, properties = {originBrokerId=NOT_SET}, readOnlyProperties = false, readOnlyBody = false, droppable = false}, redeliveryCounter = 0}


3,ActiveMQConnection类实例
ActiveMQConnection {id=ID:shijiangyong-3522-1411886444218-1:1,clientId=ID:shijiangyong-3522-1411886444218-0:1,started=true}


4,AdvisoryConsumer实现了ActiveMQDispatcher接口
    public void dispatch(MessageDispatch md) {


        // Auto ack messages when we reach 75% of the prefetch
        deliveredCounter++;
        if (deliveredCounter > (0.75 * info.getPrefetchSize())) {
            try {
                MessageAck ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, deliveredCounter);
                connection.asyncSendPacket(ack);
                deliveredCounter = 0;
            } catch (JMSException e) {
                connection.onClientInternalException(e);
            }
        }


        DataStructure o = md.getMessage().getDataStructure();
        if (o != null && o.getClass() == DestinationInfo.class) {
            processDestinationInfo((DestinationInfo)o);
        } else {
            //This can happen across networks
            if (LOG.isDebugEnabled()) {
                LOG.debug("Unexpected message was dispatched to the AdvisoryConsumer: "+md);
            }
        }


    }


附图


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值