本文整理汇总了Java中org.apache.rocketmq.common.message.MessageExt类的典型用法代码示例。如果您正苦于以下问题:Java MessageExt类的具体用法?Java MessageExt怎么用?Java MessageExt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageExt类属于org.apache.rocketmq.common.message包,在下文中一共展示了MessageExt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveBroadcastMessage
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
public void receiveBroadcastMessage(){
DefaultMQPushConsumer consumer=new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.setMessageModel(MessageModel.BROADCASTING);
try {
consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC,"*");
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
示例2: viewMessage
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
public MessageExt viewMessage(final String addr, final long phyoffset, final long timeoutMillis)
throws RemotingException, MQBrokerException, InterruptedException {
ViewMessageRequestHeader requestHeader = new ViewMessageRequestHeader();
requestHeader.setOffset(phyoffset);
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.VIEW_MESSAGE_BY_ID, requestHeader);
RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
request, timeoutMillis);
assert response != null;
switch (response.getCode()) {
case ResponseCode.SUCCESS: {
ByteBuffer byteBuffer = ByteBuffer.wrap(response.getBody());
MessageExt messageExt = MessageDecoder.clientDecode(byteBuffer, true);
return messageExt;
}
default:
break;
}
throw new MQBrokerException(response.getCode(), response.getRemark());
}
示例3: receiveMessage
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
/**
* 接收消息
*/
public void receiveMessage(){
DefaultMQPushConsumer consumer =new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
consumer.setVipChannelEnabled(false);
try {
consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, "bactch");
//程序第一次启动从消息队列头取数据
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.registerMessageListener(
new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list,ConsumeConcurrentlyContext Context) {
Message msg = list.get(0);
System.out.println(msg.toString());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
}
);
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
示例4: receiveFilterMessage
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
/**
* 接收消息
*/
public void receiveFilterMessage(){
DefaultMQPushConsumer consumer =new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
consumer.setVipChannelEnabled(false);
try {
consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, MessageSelector.bySql("a between 5 and 8"));
//程序第一次启动从消息队列头取数据
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.registerMessageListener(
new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext Context) {
Message msg = list.get(0);
System.out.println(msg.toString());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
}
);
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
示例5: doConvertMessage
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Object doConvertMessage(MessageExt messageExt) {
if (Objects.equals(messageType, MessageExt.class)) {
return messageExt;
} else {
String str = new String(messageExt.getBody(), Charset.forName(charset));
if (Objects.equals(messageType, String.class)) {
return str;
} else {
// if msgType not string, use objectMapper change it.
try {
return objectMapper.readValue(str, messageType);
} catch (Exception e) {
log.info("convert failed. str:{}, msgType:{}", str, messageType);
throw new RuntimeException("cannot convert message to " + messageType, e);
}
}
}
}
开发者ID:QianmiOpen,项目名称:spring-boot-starter-rocketmq,代码行数:20,代码来源:DefaultRocketMQListenerContainer.java
示例6: sendMsg
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
private void sendMsg(final DefaultMQAdminExt defaultMQAdminExt, final DefaultMQProducer defaultMQProducer,
final String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
try {
MessageExt msg = defaultMQAdminExt.viewMessage(msgId);
if (msg != null) {
// resend msg by id
System.out.printf("prepare resend msg. originalMsgId=" + msgId);
SendResult result = defaultMQProducer.send(msg);
System.out.printf("%s", result);
} else {
System.out.printf("no message. msgId=" + msgId);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: main
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroupNamecc4");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
File classFile = new File(classLoader.getResource("MessageFilterImpl.java").getFile());
String filterCode = MixAll.file2String(classFile);
consumer.subscribe("TopicTest", "org.apache.rocketmq.example.filter.MessageFilterImpl",
filterCode);
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
ConsumeConcurrentlyContext context) {
System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
System.out.printf("Consumer Started.%n");
}
示例8: testPullMessage_SuccessWithOrderlyService
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
@Test
public void testPullMessage_SuccessWithOrderlyService() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final MessageExt[] messageExts = new MessageExt[1];
MessageListenerOrderly listenerOrderly = new MessageListenerOrderly() {
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
messageExts[0] = msgs.get(0);
countDownLatch.countDown();
return null;
}
};
pushConsumer.registerMessageListener(listenerOrderly);
pushConsumer.getDefaultMQPushConsumerImpl().setConsumeMessageService(new ConsumeMessageOrderlyService(pushConsumer.getDefaultMQPushConsumerImpl(), listenerOrderly));
pushConsumer.getDefaultMQPushConsumerImpl().setConsumeOrderly(true);
pushConsumer.getDefaultMQPushConsumerImpl().doRebalance();
PullMessageService pullMessageService = mQClientFactory.getPullMessageService();
pullMessageService.executePullRequestLater(createPullRequest(), 100);
countDownLatch.await(10, TimeUnit.SECONDS);
assertThat(messageExts[0].getTopic()).isEqualTo(topic);
assertThat(messageExts[0].getBody()).isEqualTo(new byte[] {'a'});
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:25,代码来源:DefaultMQPushConsumerTest.java
示例9: testQueryMsgByNullMsgId
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
@Test
public void testQueryMsgByNullMsgId() {
producer.clearMsg();
int msgSize = 20;
String errorMsgId = null;
producer.send(msgSize);
Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
MessageExt queryMsg = null;
try {
queryMsg = producer.getProducer().viewMessage(errorMsgId);
} catch (Exception e) {
}
assertThat(queryMsg).isNull();
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:17,代码来源:QueryMsgByIdExceptionIT.java
示例10: testConsumeMessage
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
@Test
public void testConsumeMessage() {
final byte[] testBody = new byte[] {'a', 'b'};
MessageExt consumedMsg = new MessageExt();
consumedMsg.setMsgId("NewMsgId");
consumedMsg.setBody(testBody);
consumedMsg.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
consumedMsg.setTopic("HELLO_QUEUE");
consumer.attachQueue("HELLO_QUEUE", new MessageListener() {
@Override
public void onMessage(final Message message, final ReceivedMessageContext context) {
assertThat(message.headers().getString(MessageHeader.MESSAGE_ID)).isEqualTo("NewMsgId");
assertThat(((BytesMessage) message).getBody()).isEqualTo(testBody);
context.ack();
}
});
((MessageListenerConcurrently) rocketmqPushConsumer
.getMessageListener()).consumeMessage(Collections.singletonList(consumedMsg), null);
}
示例11: sendMessageBack
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName)
throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
try {
String brokerAddr = (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
: RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg,
this.defaultMQPushConsumer.getConsumerGroup(), delayLevel, 5000, getMaxReconsumeTimes());
} catch (Exception e) {
log.error("sendMessageBack Exception, " + this.defaultMQPushConsumer.getConsumerGroup(), e);
Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()), msg.getBody());
String originMsgId = MessageAccessor.getOriginMessageId(msg);
MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
newMsg.setFlag(msg.getFlag());
MessageAccessor.setProperties(newMsg, msg.getProperties());
MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes() + 1));
MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(getMaxReconsumeTimes()));
newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
this.mQClientFactory.getDefaultMQProducer().send(newMsg);
}
}
示例12: testQueryMsgByErrorMsgId
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
@Test
public void testQueryMsgByErrorMsgId() {
producer.clearMsg();
int msgSize = 20;
String errorMsgId = "errorMsgId";
producer.send(msgSize);
Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
MessageExt queryMsg = null;
try {
queryMsg = producer.getProducer().viewMessage(errorMsgId);
} catch (Exception e) {
}
assertThat(queryMsg).isNull();
}
示例13: checkReconsumeTimes
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
private boolean checkReconsumeTimes(List<MessageExt> msgs) {
boolean suspend = false;
if (msgs != null && !msgs.isEmpty()) {
for (MessageExt msg : msgs) {
if (msg.getReconsumeTimes() >= getMaxReconsumeTimes()) {
MessageAccessor.setReconsumeTime(msg, String.valueOf(msg.getReconsumeTimes()));
if (!sendMessageBack(msg)) {
suspend = true;
msg.setReconsumeTimes(msg.getReconsumeTimes() + 1);
}
} else {
suspend = true;
msg.setReconsumeTimes(msg.getReconsumeTimes() + 1);
}
}
}
return suspend;
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:19,代码来源:ConsumeMessageOrderlyService.java
示例14: consumeMessage
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
ConsumeOrderlyContext context) {
for (MessageExt msg : msgs) {
if (isDebug) {
if (listnerName != null && listnerName != "") {
logger.info(listnerName + ": " + msg);
} else {
logger.info(msg);
}
}
putMsg(msg);
msgBodys.addData(new String(msg.getBody()));
originMsgs.addData(msg);
}
return ConsumeOrderlyStatus.SUCCESS;
}
示例15: init
import org.apache.rocketmq.common.message.MessageExt; //导入依赖的package包/类
@Before
public void init() {
brokerController.setMessageStore(messageStore);
when(messageStore.now()).thenReturn(System.currentTimeMillis());
Channel mockChannel = mock(Channel.class);
when(mockChannel.remoteAddress()).thenReturn(new InetSocketAddress(1024));
when(handlerContext.channel()).thenReturn(mockChannel);
when(messageStore.lookMessageByOffset(anyLong())).thenReturn(new MessageExt());
sendMessageProcessor = new SendMessageProcessor(brokerController);
}