Java Code Examples for org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader#setProperties()
The following examples show how to use
org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader#setProperties() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplyMessageProcessorTest.java From rocketmq with Apache License 2.0 | 6 votes |
private SendMessageRequestHeader createSendMessageRequestHeader() { SendMessageRequestHeader requestHeader = new SendMessageRequestHeader(); requestHeader.setProducerGroup(group); requestHeader.setTopic(topic); requestHeader.setDefaultTopic(TopicValidator.AUTO_CREATE_TOPIC_KEY_TOPIC); requestHeader.setDefaultTopicQueueNums(3); requestHeader.setQueueId(1); requestHeader.setSysFlag(0); requestHeader.setBornTimestamp(System.currentTimeMillis()); requestHeader.setFlag(124); requestHeader.setReconsumeTimes(0); Map<String, String> map = new HashMap<String, String>(); map.put(MessageConst.PROPERTY_MESSAGE_REPLY_TO_CLIENT, "127.0.0.1"); requestHeader.setProperties(MessageDecoder.messageProperties2String(map)); return requestHeader; }
Example 2
Source File: MessageRedirectManagerTest.java From DeFiBus with Apache License 2.0 | 6 votes |
private SendMessageRequestHeader createSendMsgRequestHeader() { SendMessageRequestHeader requestHeader = new SendMessageRequestHeader(); requestHeader.setProducerGroup(group); requestHeader.setTopic(topic); requestHeader.setDefaultTopic(MixAll.AUTO_CREATE_TOPIC_KEY_TOPIC); requestHeader.setDefaultTopicQueueNums(3); requestHeader.setQueueId(1); requestHeader.setSysFlag(0); requestHeader.setBornTimestamp(System.currentTimeMillis()); requestHeader.setFlag(124); Message msg = new Message(); msg.putUserProperty(DeFiBusConstant.KEY, DeFiBusConstant.REPLY); msg.putUserProperty(DeFiBusConstant.PROPERTY_MESSAGE_REPLY_TO, clientId); msg.setBody(new String("abcd").getBytes()); requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties())); return requestHeader; }
Example 3
Source File: DeFiReplyMessageProcessorTest.java From DeFiBus with Apache License 2.0 | 6 votes |
private SendMessageRequestHeader createSendMsgRequestHeader() { SendMessageRequestHeader requestHeader = new SendMessageRequestHeader(); requestHeader.setProducerGroup(group); requestHeader.setTopic(topic); requestHeader.setDefaultTopic(MixAll.AUTO_CREATE_TOPIC_KEY_TOPIC); requestHeader.setDefaultTopicQueueNums(3); requestHeader.setQueueId(1); requestHeader.setSysFlag(0); requestHeader.setBornTimestamp(System.currentTimeMillis()); requestHeader.setFlag(124); Message msg = new Message(); msg.putUserProperty(DeFiBusConstant.KEY, DeFiBusConstant.REPLY); msg.putUserProperty(DeFiBusConstant.PROPERTY_MESSAGE_REPLY_TO, clientId); msg.setBody(new String("abcd").getBytes()); requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties())); return requestHeader; }
Example 4
Source File: AbstractSendMessageProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { final SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (null != requestHeader) { context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); } hook.sendMessageBefore(context); if (requestHeader != null) { requestHeader.setProperties(context.getMsgProps()); } } catch (Throwable e) { // Ignore } } } }
Example 5
Source File: MessageSendInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { Message message = (Message) allArguments[2]; ContextCarrier contextCarrier = new ContextCarrier(); String namingServiceAddress = String.valueOf(objInst.getSkyWalkingDynamicField()); AbstractSpan span = ContextManager.createExitSpan(buildOperationName(message.getTopic()), contextCarrier, namingServiceAddress); span.setComponent(ComponentsDefine.ROCKET_MQ_PRODUCER); Tags.MQ_BROKER.set(span, (String) allArguments[0]); Tags.MQ_TOPIC.set(span, message.getTopic()); SpanLayer.asMQ(span); SendMessageRequestHeader requestHeader = (SendMessageRequestHeader) allArguments[3]; StringBuilder properties = new StringBuilder(requestHeader.getProperties()); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); if (!StringUtil.isEmpty(next.getHeadValue())) { properties.append(next.getHeadKey()); properties.append(NAME_VALUE_SEPARATOR); properties.append(next.getHeadValue()); properties.append(PROPERTY_SEPARATOR); } } requestHeader.setProperties(properties.toString()); if (allArguments[6] != null) { ((EnhancedInstance) allArguments[6]).setSkyWalkingDynamicField(new SendCallBackEnhanceInfo(message.getTopic(), ContextManager .capture())); } }
Example 6
Source File: SendMessageProcessorTest.java From rocketmq with Apache License 2.0 | 5 votes |
private RemotingCommand createSendTransactionMsgCommand(int requestCode) { SendMessageRequestHeader header = createSendMsgRequestHeader(); int sysFlag = header.getSysFlag(); Map<String, String> oriProps = MessageDecoder.string2messageProperties(header.getProperties()); oriProps.put(MessageConst.PROPERTY_TRANSACTION_PREPARED, "true"); header.setProperties(MessageDecoder.messageProperties2String(oriProps)); sysFlag |= MessageSysFlag.TRANSACTION_PREPARED_TYPE; header.setSysFlag(sysFlag); RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, header); request.setBody(new byte[] {'a'}); request.makeCustomHeaderToNet(); return request; }
Example 7
Source File: AbstractSendMessageProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { final SendMessageRequestHeader requestHeader = parseRequestHeader(request); String namespace = NamespaceUtil.getNamespaceFromResource(requestHeader.getTopic()); if (null != requestHeader) { context.setNamespace(namespace); context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); } hook.sendMessageBefore(context); if (requestHeader != null) { requestHeader.setProperties(context.getMsgProps()); } } catch (Throwable e) { // Ignore } } } }
Example 8
Source File: AbstractSendMessageProcessor.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { final SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (null != requestHeader) { context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); } hook.sendMessageBefore(context); if (requestHeader != null) { requestHeader.setProperties(context.getMsgProps()); } } catch (Throwable e) { // Ignore } } } }
Example 9
Source File: AbstractSendMessageProcessor.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { final SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (null != requestHeader) { context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); } hook.sendMessageBefore(context); if (requestHeader != null) { requestHeader.setProperties(context.getMsgProps()); } } catch (Throwable e) { // Ignore } } } }
Example 10
Source File: Detector.java From DDMQ with Apache License 2.0 | 5 votes |
private SendMessageRequestHeader getMessageRequestHeader(Message msg, MessageQueue mq) { SendMessageRequestHeader requestHeader = new SendMessageRequestHeader(); requestHeader.setProducerGroup(producer.getProducerGroup()); requestHeader.setTopic(msg.getTopic()); requestHeader.setDefaultTopic(producer.getCreateTopicKey()); requestHeader.setDefaultTopicQueueNums(producer.getDefaultTopicQueueNums()); requestHeader.setQueueId(mq.getQueueId()); requestHeader.setSysFlag(0); requestHeader.setBornTimestamp(System.currentTimeMillis()); requestHeader.setFlag(msg.getFlag()); requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties())); requestHeader.setReconsumeTimes(0); requestHeader.setUnitMode(producer.isUnitMode()); return requestHeader; }
Example 11
Source File: AbstractSendMessageProcessor.java From DDMQ with Apache License 2.0 | 5 votes |
public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { final SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (null != requestHeader) { context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); } hook.sendMessageBefore(context); if (requestHeader != null) { requestHeader.setProperties(context.getMsgProps()); } } catch (Throwable e) { // Ignore } } } }
Example 12
Source File: AbstractSendMessageProcessor.java From DDMQ with Apache License 2.0 | 5 votes |
public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { final SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (null != requestHeader) { context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); } hook.sendMessageBefore(context); if (requestHeader != null) { requestHeader.setProperties(context.getMsgProps()); } } catch (Throwable e) { // Ignore } } } }
Example 13
Source File: SendMessageProcessorTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
private RemotingCommand createSendTransactionMsgCommand(int requestCode) { SendMessageRequestHeader header = createSendMsgRequestHeader(); int sysFlag = header.getSysFlag(); Map<String, String> oriProps = MessageDecoder.string2messageProperties(header.getProperties()); oriProps.put(MessageConst.PROPERTY_TRANSACTION_PREPARED, "true"); header.setProperties(MessageDecoder.messageProperties2String(oriProps)); sysFlag |= MessageSysFlag.TRANSACTION_PREPARED_TYPE; header.setSysFlag(sysFlag); RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, header); request.setBody(new byte[] {'a'}); request.makeCustomHeaderToNet(); return request; }
Example 14
Source File: AbstractSendMessageProcessor.java From rocketmq-read with Apache License 2.0 | 5 votes |
/** * 执行前置的hook * @param ctx ; * @param request ; * @param context ; */ public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { final SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (null != requestHeader) { context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); } hook.sendMessageBefore(context); if (requestHeader != null) { requestHeader.setProperties(context.getMsgProps()); } } catch (Throwable e) { // Ignore } } } }
Example 15
Source File: SendMessageProcessorTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
private RemotingCommand createSendTransactionMsgCommand(int requestCode) { SendMessageRequestHeader header = createSendMsgRequestHeader(); int sysFlag = header.getSysFlag(); Map<String, String> oriProps = MessageDecoder.string2messageProperties(header.getProperties()); oriProps.put(MessageConst.PROPERTY_TRANSACTION_PREPARED, "true"); header.setProperties(MessageDecoder.messageProperties2String(oriProps)); sysFlag |= MessageSysFlag.TRANSACTION_PREPARED_TYPE; header.setSysFlag(sysFlag); RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, header); request.setBody(new byte[] {'a'}); request.makeCustomHeaderToNet(); return request; }
Example 16
Source File: AbstractSendMessageProcessor.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { // 解析消息头,对序列化的优化 final SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (null != requestHeader) { context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); } // 执行发送消息之前的钩子方法 hook.sendMessageBefore(context); if (requestHeader != null) { requestHeader.setProperties(context.getMsgProps()); } } catch (Throwable e) { // Ignore } } } }
Example 17
Source File: Detector.java From DDMQ with Apache License 2.0 | 5 votes |
private SendMessageRequestHeader getMessageRequestHeader(Message msg, MessageQueue mq) { SendMessageRequestHeader requestHeader = new SendMessageRequestHeader(); requestHeader.setProducerGroup(producer.getProducerGroup()); requestHeader.setTopic(msg.getTopic()); requestHeader.setDefaultTopic(producer.getCreateTopicKey()); requestHeader.setDefaultTopicQueueNums(producer.getDefaultTopicQueueNums()); requestHeader.setQueueId(mq.getQueueId()); requestHeader.setSysFlag(0); requestHeader.setBornTimestamp(System.currentTimeMillis()); requestHeader.setFlag(msg.getFlag()); requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties())); requestHeader.setReconsumeTimes(0); requestHeader.setUnitMode(producer.isUnitMode()); return requestHeader; }