當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultMQProducerImpl類代碼示例

本文整理匯總了Java中org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl的典型用法代碼示例。如果您正苦於以下問題:Java DefaultMQProducerImpl類的具體用法?Java DefaultMQProducerImpl怎麽用?Java DefaultMQProducerImpl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DefaultMQProducerImpl類屬於org.apache.rocketmq.client.impl.producer包,在下文中一共展示了DefaultMQProducerImpl類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的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: registerProducer

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的package包/類
public boolean registerProducer(final String group, final DefaultMQProducerImpl producer) {
    if (null == group || null == producer) {
        return false;
    }

    MQProducerInner prev = this.producerTable.putIfAbsent(group, producer);
    if (prev != null) {
        log.warn("the producer group[{}] exist already.", group);
        return false;
    }

    return true;
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:14,代碼來源:MQClientInstance.java

示例3: sendMessage

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的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 SendMessageContext context, // 7
                              final DefaultMQProducerImpl producer // 8
) throws RemotingException, MQBrokerException, InterruptedException {
    return sendMessage(addr, brokerName, msg, requestHeader, timeoutMillis, communicationMode, null, null, null, 0, context, producer);
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:13,代碼來源:MQClientAPIImpl.java

示例4: testRegisterProducer

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的package包/類
@Test
public void testRegisterProducer() {
    boolean flag = mqClientInstance.registerProducer(group, mock(DefaultMQProducerImpl.class));
    assertThat(flag).isTrue();

    flag = mqClientInstance.registerProducer(group, mock(DefaultMQProducerImpl.class));
    assertThat(flag).isFalse();

    mqClientInstance.unregisterProducer(group);
    flag = mqClientInstance.registerProducer(group, mock(DefaultMQProducerImpl.class));
    assertThat(flag).isTrue();
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:13,代碼來源:MQClientInstanceTest.java

示例5: sendMessage

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的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 SendMessageContext context, // 7
    final DefaultMQProducerImpl producer // 8
) throws RemotingException, MQBrokerException, InterruptedException {
    return sendMessage(addr, brokerName, msg, requestHeader, timeoutMillis, communicationMode, null, null, null, 0, context, producer);
}
 
開發者ID:lyy4j,項目名稱:rmq4note,代碼行數:13,代碼來源:MQClientAPIImpl.java

示例6: sendMessage

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的package包/類
public SendResult sendMessage(
    final String addr,
    final String brokerName,
    final Message msg,
    final SendMessageRequestHeader requestHeader,
    final long timeoutMillis,
    final CommunicationMode communicationMode,
    final SendMessageContext context,
    final DefaultMQProducerImpl producer
) throws RemotingException, MQBrokerException, InterruptedException {
    return sendMessage(addr, brokerName, msg, requestHeader, timeoutMillis, communicationMode, null, null, null, 0, context, producer);
}
 
開發者ID:apache,項目名稱:rocketmq,代碼行數:13,代碼來源:MQClientAPIImpl.java

示例7: getDefaultMQProducerImpl

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的package包/類
public DefaultMQProducerImpl getDefaultMQProducerImpl() {
    return defaultMQProducerImpl;
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:4,代碼來源:DefaultMQProducer.java

示例8: getProducer

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的package包/類
public DefaultMQProducerImpl getProducer() {
    return producer;
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:4,代碼來源:SendMessageContext.java

示例9: setProducer

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的package包/類
public void setProducer(final DefaultMQProducerImpl producer) {
    this.producer = producer;
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:4,代碼來源:SendMessageContext.java

示例10: sendMessageAsync

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的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

示例11: sendMessageAsync

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的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

示例12: DefaultMQProducer

import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; //導入依賴的package包/類
/**
 * Constructor specifying both producer group and RPC hook.
 *
 * @param producerGroup Producer group, see the name-sake field.
 * @param rpcHook RPC hook to execute per each remoting command execution.
 */
public DefaultMQProducer(final String producerGroup, RPCHook rpcHook) {
    this.producerGroup = producerGroup;
    defaultMQProducerImpl = new DefaultMQProducerImpl(this, rpcHook);
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:11,代碼來源:DefaultMQProducer.java


注:本文中的org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。