当前位置: 首页>>代码示例>>Java>>正文


Java TopicPublishInfo类代码示例

本文整理汇总了Java中org.apache.rocketmq.client.impl.producer.TopicPublishInfo的典型用法代码示例。如果您正苦于以下问题:Java TopicPublishInfo类的具体用法?Java TopicPublishInfo怎么用?Java TopicPublishInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TopicPublishInfo类属于org.apache.rocketmq.client.impl.producer包,在下文中一共展示了TopicPublishInfo类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; //导入依赖的package包/类
@Before
public void init() throws Exception {
    String producerGroupTemp = producerGroupPrefix + System.currentTimeMillis();
    producer = new DefaultMQProducer(producerGroupTemp);
    producer.setNamesrvAddr("127.0.0.1:9876");
    message = new Message(topic, new byte[] {'a'});
    zeroMsg = new Message(topic, new byte[] {});

    producer.start();

    Field field = DefaultMQProducerImpl.class.getDeclaredField("mQClientFactory");
    field.setAccessible(true);
    field.set(producer.getDefaultMQProducerImpl(), mQClientFactory);

    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mQClientFactory, mQClientAPIImpl);

    producer.getDefaultMQProducerImpl().getmQClientFactory().registerProducer(producerGroupTemp, producer.getDefaultMQProducerImpl());

    when(mQClientAPIImpl.sendMessage(anyString(), anyString(), any(Message.class), any(SendMessageRequestHeader.class), anyLong(), any(CommunicationMode.class),
        nullable(SendMessageContext.class), any(DefaultMQProducerImpl.class))).thenCallRealMethod();
    when(mQClientAPIImpl.sendMessage(anyString(), anyString(), any(Message.class), any(SendMessageRequestHeader.class), anyLong(), any(CommunicationMode.class),
        nullable(SendCallback.class), nullable(TopicPublishInfo.class), nullable(MQClientInstance.class), anyInt(), nullable(SendMessageContext.class), any(DefaultMQProducerImpl.class)))
        .thenReturn(createSendResult(SendStatus.SEND_OK));
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:27,代码来源:DefaultMQProducerTest.java

示例2: fetchPublishMessageQueues

import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; //导入依赖的package包/类
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException {
    try {
        TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis);
        if (topicRouteData != null) {
            TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);
            if (topicPublishInfo != null && topicPublishInfo.ok()) {
                return topicPublishInfo.getMessageQueueList();
            }
        }
    } catch (Exception e) {
        throw new MQClientException("Can not find Message Queue for this topic, " + topic, e);
    }

    throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:16,代码来源:MQAdminImpl.java

示例3: testTopicRouteData2TopicPublishInfo

import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; //导入依赖的package包/类
@Test
public void testTopicRouteData2TopicPublishInfo() {
    TopicRouteData topicRouteData = new TopicRouteData();

    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    List<BrokerData> brokerDataList = new ArrayList<BrokerData>();
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("BrokerA");
    brokerData.setCluster("DefaultCluster");
    HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
    brokerAddrs.put(0L, "127.0.0.1:10911");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDataList.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDataList);

    List<QueueData> queueDataList = new ArrayList<QueueData>();
    QueueData queueData = new QueueData();
    queueData.setBrokerName("BrokerA");
    queueData.setPerm(6);
    queueData.setReadQueueNums(3);
    queueData.setWriteQueueNums(4);
    queueData.setTopicSynFlag(0);
    queueDataList.add(queueData);
    topicRouteData.setQueueDatas(queueDataList);

    TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);

    assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse();
    assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:31,代码来源:MQClientInstanceTest.java

示例4: testTopicRouteData2TopicPublishInfo

import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; //导入依赖的package包/类
@Test
public void testTopicRouteData2TopicPublishInfo() {
    TopicRouteData topicRouteData = new TopicRouteData();

    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    List<BrokerData> brokerDataList = new ArrayList<>();
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("BrokerA");
    brokerData.setCluster("DefaultCluster");
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(0L, "127.0.0.1:10911");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDataList.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDataList);

    List<QueueData> queueDataList = new ArrayList<>();
    QueueData queueData = new QueueData();
    queueData.setBrokerName("BrokerA");
    queueData.setPerm(6);
    queueData.setReadQueueNums(3);
    queueData.setWriteQueueNums(4);
    queueData.setTopicSynFlag(0);
    queueDataList.add(queueData);
    topicRouteData.setQueueDatas(queueDataList);

    TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);

    assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse();
    assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4);
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:31,代码来源:MQClientInstanceTest.java

示例5: sendMessage

import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; //导入依赖的package包/类
public SendResult sendMessage(//
    final String addr, // 1
    final String brokerName, // 2
    final Message msg, // 3
    final SendMessageRequestHeader requestHeader, // 4
    final long timeoutMillis, // 5
    final CommunicationMode communicationMode, // 6
    final SendCallback sendCallback, // 7
    final TopicPublishInfo topicPublishInfo, // 8
    final MQClientInstance instance, // 9
    final int retryTimesWhenSendFailed, // 10
    final SendMessageContext context, // 11
    final DefaultMQProducerImpl producer // 12
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = null;
    if (sendSmartMsg || msg instanceof MessageBatch) {
        SendMessageRequestHeaderV2 requestHeaderV2 = SendMessageRequestHeaderV2.createSendMessageRequestHeaderV2(requestHeader);
        request = RemotingCommand.createRequestCommand(msg instanceof MessageBatch ? RequestCode.SEND_BATCH_MESSAGE : RequestCode.SEND_MESSAGE_V2, requestHeaderV2);
    } else {
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE, requestHeader);
    }

    request.setBody(msg.getBody());

    switch (communicationMode) {
        case ONEWAY:
            this.remotingClient.invokeOneway(addr, request, timeoutMillis);
            return null;
        case ASYNC:
            final AtomicInteger times = new AtomicInteger();
            this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback, topicPublishInfo, instance,
                retryTimesWhenSendFailed, times, context, producer);
            return null;
        case SYNC:
            return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request);
        default:
            assert false;
            break;
    }

    return null;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:43,代码来源:MQClientAPIImpl.java

示例6: sendMessageAsync

import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; //导入依赖的package包/类
private void sendMessageAsync(//
    final String addr, //
    final String brokerName, //
    final Message msg, //
    final long timeoutMillis, //
    final RemotingCommand request, //
    final SendCallback sendCallback, //
    final TopicPublishInfo topicPublishInfo, //
    final MQClientInstance instance, //
    final int retryTimesWhenSendFailed, //
    final AtomicInteger times, //
    final SendMessageContext context, //
    final DefaultMQProducerImpl producer //
) throws InterruptedException, RemotingException {
    this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() {
        @Override
        public void operationComplete(ResponseFuture responseFuture) {
            RemotingCommand response = responseFuture.getResponseCommand();
            if (null == sendCallback && response != null) {

                try {
                    SendResult sendResult = MQClientAPIImpl.this.processSendResponse(brokerName, msg, response);
                    if (context != null && sendResult != null) {
                        context.setSendResult(sendResult);
                        context.getProducer().executeSendMessageHookAfter(context);
                    }
                } catch (Throwable e) {
                    //
                }

                producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), false);
                return;
            }

            if (response != null) {
                try {
                    SendResult sendResult = MQClientAPIImpl.this.processSendResponse(brokerName, msg, response);
                    assert sendResult != null;
                    if (context != null) {
                        context.setSendResult(sendResult);
                        context.getProducer().executeSendMessageHookAfter(context);
                    }

                    try {
                        sendCallback.onSuccess(sendResult);
                    } catch (Throwable e) {
                    }

                    producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), false);
                } catch (Exception e) {
                    producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), true);
                    onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance,
                        retryTimesWhenSendFailed, times, e, context, false, producer);
                }
            } else {
                producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), true);
                if (!responseFuture.isSendRequestOK()) {
                    MQClientException ex = new MQClientException("send request failed", responseFuture.getCause());
                    onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance,
                        retryTimesWhenSendFailed, times, ex, context, true, producer);
                } else if (responseFuture.isTimeout()) {
                    MQClientException ex = new MQClientException("wait response timeout " + responseFuture.getTimeoutMillis() + "ms",
                        responseFuture.getCause());
                    onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance,
                        retryTimesWhenSendFailed, times, ex, context, true, producer);
                } else {
                    MQClientException ex = new MQClientException("unknow reseaon", responseFuture.getCause());
                    onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance,
                        retryTimesWhenSendFailed, times, ex, context, true, producer);
                }
            }
        }
    });
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:75,代码来源:MQClientAPIImpl.java

示例7: sendMessage

import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; //导入依赖的package包/类
public SendResult sendMessage(//
    final String addr, // 1
    final String brokerName, // 2
    final Message msg, // 3
    final SendMessageRequestHeader requestHeader, // 4
    final long timeoutMillis, // 5
    final CommunicationMode communicationMode, // 6
    final SendCallback sendCallback, // 7
    final TopicPublishInfo topicPublishInfo, // 8
    final MQClientInstance instance, // 9
    final int retryTimesWhenSendFailed, // 10
    final SendMessageContext context, // 11
    final DefaultMQProducerImpl producer // 12
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = null;

    //sendSmartMsg default value:true,通过缩短参数名称,加快json的解析速度
    if (sendSmartMsg) {
        SendMessageRequestHeaderV2 requestHeaderV2 = SendMessageRequestHeaderV2.createSendMessageRequestHeaderV2(requestHeader);
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE_V2, requestHeaderV2);
    } else {
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE, requestHeader);
    }

    request.setBody(msg.getBody());

    switch (communicationMode) {
        case ONEWAY:
            this.remotingClient.invokeOneway(addr, request, timeoutMillis);
            return null;
        case ASYNC:
            final AtomicInteger times = new AtomicInteger();
            this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback, topicPublishInfo, instance,
                retryTimesWhenSendFailed, times, context, producer);
            return null;
        case SYNC:
            return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request);
        default:
            assert false;
            break;
    }

    return null;
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:45,代码来源:MQClientAPIImpl.java

示例8: sendMessage

import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; //导入依赖的package包/类
public SendResult sendMessage(
    final String addr,
    final String brokerName,
    final Message msg,
    final SendMessageRequestHeader requestHeader,
    final long timeoutMillis,
    final CommunicationMode communicationMode,
    final SendCallback sendCallback,
    final TopicPublishInfo topicPublishInfo,
    final MQClientInstance instance,
    final int retryTimesWhenSendFailed,
    final SendMessageContext context,
    final DefaultMQProducerImpl producer
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = null;
    if (sendSmartMsg || msg instanceof MessageBatch) {
        SendMessageRequestHeaderV2 requestHeaderV2 = SendMessageRequestHeaderV2.createSendMessageRequestHeaderV2(requestHeader);
        request = RemotingCommand.createRequestCommand(msg instanceof MessageBatch ? RequestCode.SEND_BATCH_MESSAGE : RequestCode.SEND_MESSAGE_V2, requestHeaderV2);
    } else {
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE, requestHeader);
    }

    request.setBody(msg.getBody());

    switch (communicationMode) {
        case ONEWAY:
            this.remotingClient.invokeOneway(addr, request, timeoutMillis);
            return null;
        case ASYNC:
            final AtomicInteger times = new AtomicInteger();
            this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback, topicPublishInfo, instance,
                retryTimesWhenSendFailed, times, context, producer);
            return null;
        case SYNC:
            return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request);
        default:
            assert false;
            break;
    }

    return null;
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:43,代码来源:MQClientAPIImpl.java

示例9: sendMessageAsync

import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; //导入依赖的package包/类
private void sendMessageAsync(
    final String addr,
    final String brokerName,
    final Message msg,
    final long timeoutMillis,
    final RemotingCommand request,
    final SendCallback sendCallback,
    final TopicPublishInfo topicPublishInfo,
    final MQClientInstance instance,
    final int retryTimesWhenSendFailed,
    final AtomicInteger times,
    final SendMessageContext context,
    final DefaultMQProducerImpl producer
) throws InterruptedException, RemotingException {
    this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() {
        @Override
        public void operationComplete(ResponseFuture responseFuture) {
            RemotingCommand response = responseFuture.getResponseCommand();
            if (null == sendCallback && response != null) {

                try {
                    SendResult sendResult = MQClientAPIImpl.this.processSendResponse(brokerName, msg, response);
                    if (context != null && sendResult != null) {
                        context.setSendResult(sendResult);
                        context.getProducer().executeSendMessageHookAfter(context);
                    }
                } catch (Throwable e) {
                }

                producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), false);
                return;
            }

            if (response != null) {
                try {
                    SendResult sendResult = MQClientAPIImpl.this.processSendResponse(brokerName, msg, response);
                    assert sendResult != null;
                    if (context != null) {
                        context.setSendResult(sendResult);
                        context.getProducer().executeSendMessageHookAfter(context);
                    }

                    try {
                        sendCallback.onSuccess(sendResult);
                    } catch (Throwable e) {
                    }

                    producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), false);
                } catch (Exception e) {
                    producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), true);
                    onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance,
                        retryTimesWhenSendFailed, times, e, context, false, producer);
                }
            } else {
                producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), true);
                if (!responseFuture.isSendRequestOK()) {
                    MQClientException ex = new MQClientException("send request failed", responseFuture.getCause());
                    onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance,
                        retryTimesWhenSendFailed, times, ex, context, true, producer);
                } else if (responseFuture.isTimeout()) {
                    MQClientException ex = new MQClientException("wait response timeout " + responseFuture.getTimeoutMillis() + "ms",
                        responseFuture.getCause());
                    onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance,
                        retryTimesWhenSendFailed, times, ex, context, true, producer);
                } else {
                    MQClientException ex = new MQClientException("unknow reseaon", responseFuture.getCause());
                    onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance,
                        retryTimesWhenSendFailed, times, ex, context, true, producer);
                }
            }
        }
    });
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:74,代码来源:MQClientAPIImpl.java


注:本文中的org.apache.rocketmq.client.impl.producer.TopicPublishInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。