org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader Java Examples
The following examples show how to use
org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader.
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: 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 #2
Source File: DefaultMQProducerTest.java From DDMQ with Apache License 2.0 | 6 votes |
@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)); }
Example #3
Source File: MQClientAPIImplTest.java From rocketmq with Apache License 2.0 | 6 votes |
@Test public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); return createSuccessResponse(request); } }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); SendMessageRequestHeader requestHeader = createSendMessageRequestHeader(); SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader, 3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl); assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); assertThat(sendResult.getOffsetMsgId()).isEqualTo("123"); assertThat(sendResult.getQueueOffset()).isEqualTo(123L); assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1); }
Example #4
Source File: SendMessageProcessorTest.java From DDMQ with Apache License 2.0 | 6 votes |
private RemotingCommand createSendMsgCommand(int requestCode) { SendMessageRequestHeader requestHeader = new SendMessageRequestHeader(); requestHeader.setProducerGroup(group); requestHeader.setTopic(topic); requestHeader.setDefaultTopic(MixAll.DEFAULT_TOPIC); requestHeader.setDefaultTopicQueueNums(3); requestHeader.setQueueId(1); requestHeader.setSysFlag(0); requestHeader.setBornTimestamp(System.currentTimeMillis()); requestHeader.setFlag(124); requestHeader.setReconsumeTimes(0); RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, requestHeader); request.setBody(new byte[] {'a'}); request.makeCustomHeaderToNet(); return request; }
Example #5
Source File: SendMessageProcessor.java From rocketmq_trans_message with Apache License 2.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext; switch (request.getCode()) { case RequestCode.CONSUMER_SEND_MSG_BACK: return this.consumerSendMsgBack(ctx, request); default: SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (requestHeader == null) { return null; } mqtraceContext = buildMsgContext(ctx, requestHeader); this.executeSendMessageHookBefore(ctx, request, mqtraceContext); final RemotingCommand response = this.sendMessage(ctx, request, mqtraceContext, requestHeader); this.executeSendMessageHookAfter(response, mqtraceContext); return response; } }
Example #6
Source File: MQClientAPIImplTest.java From DDMQ with Apache License 2.0 | 6 votes |
@Test public void testSendMessageSync_WithException() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class); response.setCode(ResponseCode.SYSTEM_ERROR); response.setOpaque(request.getOpaque()); response.setRemark("Broker is broken."); return response; } }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); SendMessageRequestHeader requestHeader = createSendMessageRequestHeader(); try { mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader, 3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl); failBecauseExceptionWasNotThrown(MQBrokerException.class); } catch (MQBrokerException e) { assertThat(e).hasMessageContaining("Broker is broken."); } }
Example #7
Source File: SendMessageProcessor.java From rocketmq with Apache License 2.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext; switch (request.getCode()) { case RequestCode.CONSUMER_SEND_MSG_BACK: return this.consumerSendMsgBack(ctx, request); default: // 解析请求 SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (requestHeader == null) { return null; } // 建立消息上下文 mqtraceContext = buildMsgContext(ctx, requestHeader); // hook:处理发送消息前逻辑 this.executeSendMessageHookBefore(ctx, request, mqtraceContext); // 处理发送消息逻辑 final RemotingCommand response = this.sendMessage(ctx, request, mqtraceContext, requestHeader); // hook:处理发送消息后逻辑 this.executeSendMessageHookAfter(response, mqtraceContext); return response; } }
Example #8
Source File: SendMessageProcessorTest.java From rocketmq with Apache License 2.0 | 6 votes |
private RemotingCommand createSendMsgCommand(int requestCode) { SendMessageRequestHeader requestHeader = new SendMessageRequestHeader(); requestHeader.setProducerGroup(group); requestHeader.setTopic(topic); requestHeader.setDefaultTopic(MixAll.DEFAULT_TOPIC); requestHeader.setDefaultTopicQueueNums(3); requestHeader.setQueueId(1); requestHeader.setSysFlag(0); requestHeader.setBornTimestamp(System.currentTimeMillis()); requestHeader.setFlag(124); requestHeader.setReconsumeTimes(0); RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, requestHeader); request.setBody(new byte[] {'a'}); request.makeCustomHeaderToNet(); return request; }
Example #9
Source File: AbstractSendMessageProcessor.java From DDMQ with Apache License 2.0 | 6 votes |
protected RemotingCommand msgContentCheck(final ChannelHandlerContext ctx, final SendMessageRequestHeader requestHeader, RemotingCommand request, final RemotingCommand response) { if (requestHeader.getTopic().length() > Byte.MAX_VALUE) { log.warn("putMessage message topic length too long {}", requestHeader.getTopic().length()); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } if (requestHeader.getProperties() != null && requestHeader.getProperties().length() > Short.MAX_VALUE) { log.warn("putMessage message properties length too long {}", requestHeader.getProperties().length()); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } if (request.getBody().length > DBMsgConstants.MAX_BODY_SIZE) { log.warn(" topic {} msg body size {} from {}", requestHeader.getTopic(), request.getBody().length, ChannelUtil.getRemoteIp(ctx.channel())); response.setRemark("msg body must be less 64KB"); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } return response; }
Example #10
Source File: MQClientAPIImplTest.java From DDMQ with Apache License 2.0 | 6 votes |
@Test public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); return createSuccessResponse(request); } }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); SendMessageRequestHeader requestHeader = createSendMessageRequestHeader(); SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader, 3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl); assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); assertThat(sendResult.getOffsetMsgId()).isEqualTo("123"); assertThat(sendResult.getQueueOffset()).isEqualTo(123L); assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1); }
Example #11
Source File: DefaultMQProducerTest.java From rocketmq with Apache License 2.0 | 6 votes |
@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)); }
Example #12
Source File: MQClientAPIImplTest.java From rocketmq_trans_message with Apache License 2.0 | 6 votes |
@Test public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); return createSuccessResponse(request); } }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); SendMessageRequestHeader requestHeader = createSendMessageRequestHeader(); SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader, 3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl); assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); assertThat(sendResult.getOffsetMsgId()).isEqualTo("123"); assertThat(sendResult.getQueueOffset()).isEqualTo(123L); assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1); }
Example #13
Source File: MQClientAPIImplTest.java From rocketmq-4.3.0 with Apache License 2.0 | 6 votes |
@Test public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); return createSuccessResponse(request); } }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); SendMessageRequestHeader requestHeader = createSendMessageRequestHeader(); SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader, 3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl); assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); assertThat(sendResult.getOffsetMsgId()).isEqualTo("123"); assertThat(sendResult.getQueueOffset()).isEqualTo(123L); assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1); }
Example #14
Source File: MQClientAPIImplTest.java From rocketmq-4.3.0 with Apache License 2.0 | 6 votes |
@Test public void testSendMessageSync_WithException() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class); response.setCode(ResponseCode.SYSTEM_ERROR); response.setOpaque(request.getOpaque()); response.setRemark("Broker is broken."); return response; } }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); SendMessageRequestHeader requestHeader = createSendMessageRequestHeader(); try { mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader, 3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl); failBecauseExceptionWasNotThrown(MQBrokerException.class); } catch (MQBrokerException e) { assertThat(e).hasMessageContaining("Broker is broken."); } }
Example #15
Source File: MQClientAPIImplTest.java From rocketmq with Apache License 2.0 | 6 votes |
@Test public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); return createSuccessResponse(request); } }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); SendMessageRequestHeader requestHeader = createSendMessageRequestHeader(); SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader, 3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl); assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); assertThat(sendResult.getOffsetMsgId()).isEqualTo("123"); assertThat(sendResult.getQueueOffset()).isEqualTo(123L); assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1); }
Example #16
Source File: ReplyMessageProcessor.java From rocketmq with Apache License 2.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext = null; SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (requestHeader == null) { return null; } mqtraceContext = buildMsgContext(ctx, requestHeader); this.executeSendMessageHookBefore(ctx, request, mqtraceContext); RemotingCommand response = this.processReplyMessageRequest(ctx, request, mqtraceContext, requestHeader); this.executeSendMessageHookAfter(response, mqtraceContext); return response; }
Example #17
Source File: AbstractSendMessageProcessor.java From rocketmq-4.3.0 with Apache License 2.0 | 6 votes |
protected RemotingCommand msgContentCheck(final ChannelHandlerContext ctx, final SendMessageRequestHeader requestHeader, RemotingCommand request, final RemotingCommand response) { if (requestHeader.getTopic().length() > Byte.MAX_VALUE) { log.warn("putMessage message topic length too long {}", requestHeader.getTopic().length()); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } if (requestHeader.getProperties() != null && requestHeader.getProperties().length() > Short.MAX_VALUE) { log.warn("putMessage message properties length too long {}", requestHeader.getProperties().length()); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } if (request.getBody().length > DBMsgConstants.MAX_BODY_SIZE) { log.warn(" topic {} msg body size {} from {}", requestHeader.getTopic(), request.getBody().length, ChannelUtil.getRemoteIp(ctx.channel())); response.setRemark("msg body must be less 64KB"); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } return response; }
Example #18
Source File: SendMessageProcessorTest.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
private RemotingCommand createSendMsgCommand(int requestCode) { SendMessageRequestHeader requestHeader = new SendMessageRequestHeader(); requestHeader.setProducerGroup(group); requestHeader.setTopic(topic); requestHeader.setDefaultTopic(MixAll.DEFAULT_TOPIC); requestHeader.setDefaultTopicQueueNums(3); requestHeader.setQueueId(1); requestHeader.setSysFlag(0); requestHeader.setBornTimestamp(System.currentTimeMillis()); requestHeader.setFlag(124); requestHeader.setReconsumeTimes(0); RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, requestHeader); request.setBody(new byte[] {'a'}); request.makeCustomHeaderToNet(); return request; }
Example #19
Source File: MQClientAPIImplTest.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
@Test public void testSendMessageSync_WithException() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class); response.setCode(ResponseCode.SYSTEM_ERROR); response.setOpaque(request.getOpaque()); response.setRemark("Broker is broken."); return response; } }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); SendMessageRequestHeader requestHeader = createSendMessageRequestHeader(); try { mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader, 3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl); failBecauseExceptionWasNotThrown(MQBrokerException.class); } catch (MQBrokerException e) { assertThat(e).hasMessageContaining("Broker is broken."); } }
Example #20
Source File: MQClientAPIImplTest.java From rocketmq-read with Apache License 2.0 | 6 votes |
@Test public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); return createSuccessResponse(request); } }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); SendMessageRequestHeader requestHeader = createSendMessageRequestHeader(); SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader, 3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl); assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); assertThat(sendResult.getOffsetMsgId()).isEqualTo("123"); assertThat(sendResult.getQueueOffset()).isEqualTo(123L); assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1); }
Example #21
Source File: DefaultMQProducerTest.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
@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)); }
Example #22
Source File: MQClientAPIImplTest.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
@Test public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); return createSuccessResponse(request); } }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); SendMessageRequestHeader requestHeader = createSendMessageRequestHeader(); SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader, 3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl); assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); assertThat(sendResult.getOffsetMsgId()).isEqualTo("123"); assertThat(sendResult.getQueueOffset()).isEqualTo(123L); assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1); }
Example #23
Source File: DefaultMQProducerTest.java From rocketmq_trans_message with Apache License 2.0 | 6 votes |
@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)); }
Example #24
Source File: AbstractSendMessageProcessor.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
protected RemotingCommand msgContentCheck(final ChannelHandlerContext ctx, final SendMessageRequestHeader requestHeader, RemotingCommand request, final RemotingCommand response) { if (requestHeader.getTopic().length() > Byte.MAX_VALUE) { log.warn("putMessage message topic length too long {}", requestHeader.getTopic().length()); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } if (requestHeader.getProperties() != null && requestHeader.getProperties().length() > Short.MAX_VALUE) { log.warn("putMessage message properties length too long {}", requestHeader.getProperties().length()); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } if (request.getBody().length > DBMsgConstants.MAX_BODY_SIZE) { log.warn(" topic {} msg body size {} from {}", requestHeader.getTopic(), request.getBody().length, ChannelUtil.getRemoteIp(ctx.channel())); response.setRemark("msg body must be less 64KB"); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } return response; }
Example #25
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 #26
Source File: DeFiReplyMessageProcessor.java From DeFiBus with Apache License 2.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext = null; switch (request.getCode()) { case DeFiBusRequestCode.SEND_DIRECT_MESSAGE_V2: case DeFiBusRequestCode.SEND_DIRECT_MESSAGE: SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (requestHeader == null) { return null; } mqtraceContext = buildMsgContext(ctx, requestHeader); this.executeSendMessageHookBefore(ctx, request, mqtraceContext); final RemotingCommand response = this.processReplyMessageRequest(ctx, request, mqtraceContext, requestHeader); this.executeSendMessageHookAfter(response, mqtraceContext); return response; default: log.warn("Unsupported request code :" + request.getCode()); } return null; }
Example #27
Source File: DefaultMQProducerTest.java From DDMQ with Apache License 2.0 | 6 votes |
@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)); }
Example #28
Source File: MQClientAPIImplTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testSendMessageOneWay_Success() throws RemotingException, InterruptedException, MQBrokerException { doNothing().when(remotingClient).invokeOneway(anyString(), any(RemotingCommand.class), anyLong()); SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, new SendMessageRequestHeader(), 3 * 1000, CommunicationMode.ONEWAY, new SendMessageContext(), defaultMQProducerImpl); assertThat(sendResult).isNull(); }
Example #29
Source File: MessageRedirectManager.java From DeFiBus with Apache License 2.0 | 5 votes |
public RedirectResult redirectMessageToWhichQueue(SendMessageRequestHeader requestHeader, String flag) { if (hasRedirectConfig(flag, requestHeader.getTopic())) { ArrayList<Integer> grayQueueId = findCandidateQueueId(flag, requestHeader.getTopic()); if (grayQueueId.size() > 0) { int redirectQueueId = grayQueueId.get(Math.abs(random.nextInt()) % grayQueueId.size()); return new RedirectResult(RedirectStates.REDIRECT_OK, redirectQueueId); } else { return new RedirectResult(RedirectStates.NO_INSTANCE_FOUND, -1); } } else { return new RedirectResult(RedirectStates.NO_REDIRECT_CONFIG, -1); } }
Example #30
Source File: DefaultMQProducerWithTraceTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { customTraceTopicproducer = new DefaultMQProducer(producerGroupTemp, false, customerTraceTopic); normalProducer = new DefaultMQProducer(producerGroupTemp, false, ""); producer = new DefaultMQProducer(producerGroupTemp, true, ""); producer.setNamesrvAddr("127.0.0.1:9876"); normalProducer.setNamesrvAddr("127.0.0.1:9877"); customTraceTopicproducer.setNamesrvAddr("127.0.0.1:9878"); message = new Message(topic, new byte[] {'a', 'b', 'c'}); asyncTraceDispatcher = (AsyncTraceDispatcher) producer.getTraceDispatcher(); asyncTraceDispatcher.setTraceTopicName(customerTraceTopic); asyncTraceDispatcher.getHostProducer(); asyncTraceDispatcher.getHostConsumer(); traceProducer = asyncTraceDispatcher.getTraceProducer(); producer.start(); Field field = DefaultMQProducerImpl.class.getDeclaredField("mQClientFactory"); field.setAccessible(true); field.set(producer.getDefaultMQProducerImpl(), mQClientFactory); Field fieldTrace = DefaultMQProducerImpl.class.getDeclaredField("mQClientFactory"); fieldTrace.setAccessible(true); fieldTrace.set(traceProducer.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)); }