RocketMQ生产者

前言

RocketMQ生产者顶级接口是MQProducer,他有2个子类DefaultMQProducer和TransactionMQProducer
在这里插入图片描述

一、MQProducer
1.1 开启和关闭Producer
void start() throws MQClientException;
void shutdown();
1.2 单向发送消息

这种方式主要用在不特别关心发送结果的场景,例如日志发送

void sendOneway(final Message msg) throws ...;
void sendOneway(final Message msg, final MessageQueue mq) throws ...;
void sendOneway(final Message msg, final MessageQueueSelector selector, final Object arg) throws ...;
1.3 同步发送消息

这种可靠性同步地发送方式使用的比较广泛,比如:重要的消息通知,短信通知

一次发送一个

SendResult send(final Message msg) throws ...;
SendResult send(final Message msg, final long timeout) throws ...;
SendResult send(final Message msg, final MessageQueue mq) throws ...;
SendResult send(final Message msg, final MessageQueue mq, final long timeout)throws ...;
SendResult send(final Message msg, final MessageQueueSelector selector, final Object arg)throws ...;
SendResult send(final Message msg, final MessageQueueSelector selector, final Object arg, final long timeout) throws ...;

批量发送

SendResult send(final Collection<Message> msgs)throws ...;
SendResult send(final Collection<Message> msgs, final long timeout) throws ...;
SendResult send(final Collection<Message> msgs, final MessageQueue mq) throws ...;
SendResult send(final Collection<Message> msgs, final MessageQueue mq, final long timeout)throws ...;
1.4 异步步发送消息

异步消息通常用在对响应时间敏感的业务场景,即发送端不能容忍长时间地等待Broker的响应

一次发送一个

void send(final Message msg, final SendCallback sendCallback) throws ...;
void send(final Message msg, final SendCallback sendCallback, final long timeout)throws ...;
void send(final Message msg, final MessageQueue mq, final SendCallback sendCallback)throws ...;
void send(final Message msg, final MessageQueue mq, final SendCallback sendCallback, long timeout)throws ...;
void send(final Message msg, final MessageQueueSelector selector, final Object arg, final SendCallback sendCallback) throws ...;
void send(final Message msg, final MessageQueueSelector selector, final Object arg,final SendCallback sendCallback, final long timeout) throws ...;

批量发送

void send(final Collection<Message> msgs, final SendCallback sendCallback) throws ...;
void send(final Collection<Message> msgs, final SendCallback sendCallback, final long timeout)throws ...;
void send(final Collection<Message> msgs, final MessageQueue mq, final SendCallback sendCallback) throws ...;
void send(final Collection<Message> msgs, final MessageQueue mq, final SendCallback sendCallback, final long timeout) throws ...;
1.5 发送事务消息
TransactionSendResult sendMessageInTransaction(final Message msg,final Object arg) throws ... ;
TransactionSendResult sendMessageInTransaction(final Message msg, final LocalTransactionExecuter tranExecuter, final Object arg) throws ...;

1.6 获取消息列表
List<MessageQueue> fetchPublishMessageQueues(final String topic) throws MQClientException;
1.7 同步获取消息
Message request(final Message msg, final long timeout) throws ... ;
Message request(final Message msg, final MessageQueue mq, final long timeout)throws ... ;
Message request(final Message msg, final MessageQueueSelector selector, final Object arg,final long timeout) throws ... ;

1.7 异步消息
void request(final Message msg, final RequestCallback requestCallback, final long timeout)throws ... ;
void request(final Message msg, final MessageQueue mq, final RequestCallback requestCallback, long timeout)
throws ... ;
void request(final Message msg, final MessageQueueSelector selector, final Object arg,final RequestCallback requestCallback, final long timeout) throws ... ;

二、DefaultMQProducer
2.1 构造器
public DefaultMQProducer()public DefaultMQProducer(RPCHook rpcHook)public DefaultMQProducer(final String producerGroup)public DefaultMQProducer(final String producerGroup, RPCHook rpcHook, boolean enableMsgTrace,
final String customizedTraceTopic)public DefaultMQProducer(final String namespace, final String producerGroup)public DefaultMQProducer(final String producerGroup, RPCHook rpcHook)public DefaultMQProducer(final String namespace, final String producerGroup, RPCHook rpcHook)public DefaultMQProducer(final String producerGroup, boolean enableMsgTrace)public DefaultMQProducer(final String producerGroup, boolean enableMsgTrace, final String customizedTraceTopic)public DefaultMQProducer(final String namespace, final String producerGroup, RPCHook rpcHook,
boolean enableMsgTrace, final String customizedTraceTopic)
三、TransactionMQProducer
public TransactionMQProducer()public TransactionMQProducer(final String producerGroup)public TransactionMQProducer(final String namespace, final String producerGroup)public TransactionMQProducer(final String producerGroup, RPCHook rpcHook)public TransactionMQProducer(final String namespace, final String producerGroup, RPCHook rpcHook)public TransactionMQProducer(final String namespace, final String producerGroup, RPCHook rpcHook, boolean enableMsgTrace, final String customizedTraceTopic)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值