org.apache.rocketmq.client.impl.producer.TopicPublishInfo Java Examples
The following examples show how to use
org.apache.rocketmq.client.impl.producer.TopicPublishInfo.
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: 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 #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: 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 #4
Source File: BatchMQProducer.java From DDMQ with Apache License 2.0 | 6 votes |
public void send(CarreraRequest request, MessageQueueSelector messageQueueSelector) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { TopicPublishInfo topicInfo = clusterProducer.getRocketMQProducerByIndex(0).getDefaultMQProducerImpl().getTopicPublishInfoTable().get(request.getTopic()); if (topicInfo == null || !topicInfo.ok()) { //new topic sendSingleMessage(request); return; } MessageQueue mq = messageQueueSelector.select(topicInfo.getMessageQueueList(), null, request); request.setMessageQueue(mq); requestQMap.computeIfAbsent(mq.getBrokerName(), _name -> { Deque<CarreraRequest> q = new ConcurrentLinkedDeque<>(); addRequestQueue(q, _name, config.getMaxEncodeWorkerForEachBroker()); return q; }).add(request); }
Example #5
Source File: MQAdminImpl.java From rocketmq-read with Apache License 2.0 | 6 votes |
/** * 根据topic获取Publish的消息的队列详情 * @param topic topic * @return ; * @throws MQClientException ; */ public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException { try { TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); if (topicRouteData != null) { TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); if (topicPublishInfo != null && topicPublishInfo.ok()) { return topicPublishInfo.getMessageQueueList(); } } } catch (Exception e) { throw new MQClientException("Can not find Message Queue for this topic, " + topic, e); } throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null); }
Example #6
Source File: RmqSender.java From DDMQ with Apache License 2.0 | 6 votes |
public static TopicPublishInfo tryToFindTopicPublishInfo(DefaultMQProducer producer, final String topic) { TopicPublishInfo topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic); if (null == topicPublishInfo || !topicPublishInfo.ok()) { producer.getDefaultMQProducerImpl().getmQClientFactory().updateTopicRouteInfoFromNameServer(topic); topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic); } if (topicPublishInfo != null && (topicPublishInfo.isHaveTopicRouterInfo() || topicPublishInfo.ok())) { return topicPublishInfo; } else { producer.getDefaultMQProducerImpl().getmQClientFactory() .updateTopicRouteInfoFromNameServer(topic, true, producer); topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic); return topicPublishInfo; } }
Example #7
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 #8
Source File: BatchMQProducer.java From DDMQ with Apache License 2.0 | 6 votes |
public void send(CarreraRequest request, MessageQueueSelector messageQueueSelector) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { TopicPublishInfo topicInfo = clusterProducer.getRocketMQProducerByIndex(0).getDefaultMQProducerImpl().getTopicPublishInfoTable().get(request.getTopic()); if (topicInfo == null || !topicInfo.ok()) { //new topic sendSingleMessage(request); return; } MessageQueue mq = messageQueueSelector.select(topicInfo.getMessageQueueList(), null, request); request.setMessageQueue(mq); requestQMap.computeIfAbsent(mq.getBrokerName(), _name -> { Deque<CarreraRequest> q = new ConcurrentLinkedDeque<>(); addRequestQueue(q, _name, config.getMaxEncodeWorkerForEachBroker()); return q; }).add(request); }
Example #9
Source File: RmqSender.java From DDMQ with Apache License 2.0 | 6 votes |
public static TopicPublishInfo tryToFindTopicPublishInfo(DefaultMQProducer producer, final String topic) { TopicPublishInfo topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic); if (null == topicPublishInfo || !topicPublishInfo.ok()) { producer.getDefaultMQProducerImpl().getmQClientFactory().updateTopicRouteInfoFromNameServer(topic); topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic); } if (topicPublishInfo != null && (topicPublishInfo.isHaveTopicRouterInfo() || topicPublishInfo.ok())) { return topicPublishInfo; } else { producer.getDefaultMQProducerImpl().getmQClientFactory() .updateTopicRouteInfoFromNameServer(topic, true, producer); topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic); return topicPublishInfo; } }
Example #10
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 #11
Source File: MQAdminImpl.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException { try { TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); if (topicRouteData != null) { TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); if (topicPublishInfo != null && topicPublishInfo.ok()) { return topicPublishInfo.getMessageQueueList(); } } } catch (Exception e) { throw new MQClientException("Can not find Message Queue for this topic, " + topic, e); } throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null); }
Example #12
Source File: MQAdminImpl.java From DDMQ with Apache License 2.0 | 5 votes |
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException { try { TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); if (topicRouteData != null) { TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); if (topicPublishInfo != null && topicPublishInfo.ok()) { return topicPublishInfo.getMessageQueueList(); } } } catch (Exception e) { throw new MQClientException("Can not find Message Queue for this topic, " + topic, e); } throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null); }
Example #13
Source File: MQAdminImpl.java From DDMQ with Apache License 2.0 | 5 votes |
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException { try { TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); if (topicRouteData != null) { TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); if (topicPublishInfo != null && topicPublishInfo.ok()) { return topicPublishInfo.getMessageQueueList(); } } } catch (Exception e) { throw new MQClientException("Can not find Message Queue for this topic, " + topic, e); } throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null); }
Example #14
Source File: MQClientInstanceTest.java From DDMQ with Apache License 2.0 | 5 votes |
@Test public void testTopicRouteData2TopicPublishInfo() { TopicRouteData topicRouteData = new TopicRouteData(); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); List<BrokerData> brokerDataList = new ArrayList<BrokerData>(); BrokerData brokerData = new BrokerData(); brokerData.setBrokerName("BrokerA"); brokerData.setCluster("DefaultCluster"); HashMap<Long, String> brokerAddrs = new HashMap<Long, String>(); brokerAddrs.put(0L, "127.0.0.1:10911"); brokerData.setBrokerAddrs(brokerAddrs); brokerDataList.add(brokerData); topicRouteData.setBrokerDatas(brokerDataList); List<QueueData> queueDataList = new ArrayList<QueueData>(); QueueData queueData = new QueueData(); queueData.setBrokerName("BrokerA"); queueData.setPerm(6); queueData.setReadQueueNums(3); queueData.setWriteQueueNums(4); queueData.setTopicSynFlag(0); queueDataList.add(queueData); topicRouteData.setQueueDatas(queueDataList); TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse(); assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4); }
Example #15
Source File: MQAdminImpl.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException { try { TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); if (topicRouteData != null) { TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); if (topicPublishInfo != null && topicPublishInfo.ok()) { return topicPublishInfo.getMessageQueueList(); } } } catch (Exception e) { throw new MQClientException("Can not find Message Queue for this topic, " + topic, e); } throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null); }
Example #16
Source File: MQClientInstanceTest.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
@Test public void testTopicRouteData2TopicPublishInfo() { TopicRouteData topicRouteData = new TopicRouteData(); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); List<BrokerData> brokerDataList = new ArrayList<BrokerData>(); BrokerData brokerData = new BrokerData(); brokerData.setBrokerName("BrokerA"); brokerData.setCluster("DefaultCluster"); HashMap<Long, String> brokerAddrs = new HashMap<Long, String>(); brokerAddrs.put(0L, "127.0.0.1:10911"); brokerData.setBrokerAddrs(brokerAddrs); brokerDataList.add(brokerData); topicRouteData.setBrokerDatas(brokerDataList); List<QueueData> queueDataList = new ArrayList<QueueData>(); QueueData queueData = new QueueData(); queueData.setBrokerName("BrokerA"); queueData.setPerm(6); queueData.setReadQueueNums(3); queueData.setWriteQueueNums(4); queueData.setTopicSynFlag(0); queueDataList.add(queueData); topicRouteData.setQueueDatas(queueDataList); TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse(); assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4); }
Example #17
Source File: MQClientInstanceTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testTopicRouteData2TopicPublishInfo() { TopicRouteData topicRouteData = new TopicRouteData(); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); List<BrokerData> brokerDataList = new ArrayList<>(); BrokerData brokerData = new BrokerData(); brokerData.setBrokerName("BrokerA"); brokerData.setCluster("DefaultCluster"); HashMap<Long, String> brokerAddrs = new HashMap<>(); brokerAddrs.put(0L, "127.0.0.1:10911"); brokerData.setBrokerAddrs(brokerAddrs); brokerDataList.add(brokerData); topicRouteData.setBrokerDatas(brokerDataList); List<QueueData> queueDataList = new ArrayList<>(); QueueData queueData = new QueueData(); queueData.setBrokerName("BrokerA"); queueData.setPerm(6); queueData.setReadQueueNums(3); queueData.setWriteQueueNums(4); queueData.setTopicSynFlag(0); queueDataList.add(queueData); topicRouteData.setQueueDatas(queueDataList); TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse(); assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4); }
Example #18
Source File: MQClientInstanceTest.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
@Test public void testTopicRouteData2TopicPublishInfo() { TopicRouteData topicRouteData = new TopicRouteData(); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); List<BrokerData> brokerDataList = new ArrayList<>(); BrokerData brokerData = new BrokerData(); brokerData.setBrokerName("BrokerA"); brokerData.setCluster("DefaultCluster"); HashMap<Long, String> brokerAddrs = new HashMap<>(); brokerAddrs.put(0L, "127.0.0.1:10911"); brokerData.setBrokerAddrs(brokerAddrs); brokerDataList.add(brokerData); topicRouteData.setBrokerDatas(brokerDataList); List<QueueData> queueDataList = new ArrayList<>(); QueueData queueData = new QueueData(); queueData.setBrokerName("BrokerA"); queueData.setPerm(6); queueData.setReadQueueNums(3); queueData.setWriteQueueNums(4); queueData.setTopicSynFlag(0); queueDataList.add(queueData); topicRouteData.setQueueDatas(queueDataList); TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse(); assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4); }
Example #19
Source File: AsyncTraceDispatcher.java From rocketmq with Apache License 2.0 | 5 votes |
private Set<String> tryGetMessageQueueBrokerSet(DefaultMQProducerImpl producer, String topic) { Set<String> brokerSet = new HashSet<String>(); TopicPublishInfo topicPublishInfo = producer.getTopicPublishInfoTable().get(topic); if (null == topicPublishInfo || !topicPublishInfo.ok()) { producer.getTopicPublishInfoTable().putIfAbsent(topic, new TopicPublishInfo()); producer.getmQClientFactory().updateTopicRouteInfoFromNameServer(topic); topicPublishInfo = producer.getTopicPublishInfoTable().get(topic); } if (topicPublishInfo.isHaveTopicRouterInfo() || topicPublishInfo.ok()) { for (MessageQueue queue : topicPublishInfo.getMessageQueueList()) { brokerSet.add(queue.getBrokerName()); } } return brokerSet; }
Example #20
Source File: MQAdminImpl.java From rocketmq with Apache License 2.0 | 5 votes |
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException { try { TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); if (topicRouteData != null) { TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); if (topicPublishInfo != null && topicPublishInfo.ok()) { return parsePublishMessageQueues(topicPublishInfo.getMessageQueueList()); } } } catch (Exception e) { throw new MQClientException("Can not find Message Queue for this topic, " + topic, e); } throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null); }
Example #21
Source File: DefaultMQProducerTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { String producerGroupTemp = producerGroupPrefix + System.currentTimeMillis(); producer = new DefaultMQProducer(producerGroupTemp); producer.setNamesrvAddr("127.0.0.1:9876"); producer.setCompressMsgBodyOverHowmuch(16); message = new Message(topic, new byte[] {'a'}); zeroMsg = new Message(topic, new byte[] {}); bigMessage = new Message(topic, "This is a very huge message!".getBytes()); 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: 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)); }
Example #23
Source File: MQClientInstanceTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testTopicRouteData2TopicPublishInfo() { TopicRouteData topicRouteData = new TopicRouteData(); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); List<BrokerData> brokerDataList = new ArrayList<BrokerData>(); BrokerData brokerData = new BrokerData(); brokerData.setBrokerName("BrokerA"); brokerData.setCluster("DefaultCluster"); HashMap<Long, String> brokerAddrs = new HashMap<Long, String>(); brokerAddrs.put(0L, "127.0.0.1:10911"); brokerData.setBrokerAddrs(brokerAddrs); brokerDataList.add(brokerData); topicRouteData.setBrokerDatas(brokerDataList); List<QueueData> queueDataList = new ArrayList<QueueData>(); QueueData queueData = new QueueData(); queueData.setBrokerName("BrokerA"); queueData.setPerm(6); queueData.setReadQueueNums(3); queueData.setWriteQueueNums(4); queueData.setTopicSynFlag(0); queueDataList.add(queueData); topicRouteData.setQueueDatas(queueDataList); TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse(); assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4); }
Example #24
Source File: DefaultMQProducerTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { String producerGroupTemp = producerGroupPrefix + System.currentTimeMillis(); producer = new DefaultMQProducer(producerGroupTemp); producer.setNamesrvAddr("127.0.0.1:9876"); producer.setCompressMsgBodyOverHowmuch(16); message = new Message(topic, new byte[] {'a'}); zeroMsg = new Message(topic, new byte[] {}); bigMessage = new Message(topic, "This is a very huge message!".getBytes()); 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 #25
Source File: MQClientInstanceTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Test public void testTopicRouteData2TopicPublishInfo() { TopicRouteData topicRouteData = new TopicRouteData(); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); List<BrokerData> brokerDataList = new ArrayList<BrokerData>(); BrokerData brokerData = new BrokerData(); brokerData.setBrokerName("BrokerA"); brokerData.setCluster("DefaultCluster"); HashMap<Long, String> brokerAddrs = new HashMap<Long, String>(); brokerAddrs.put(0L, "127.0.0.1:10911"); brokerData.setBrokerAddrs(brokerAddrs); brokerDataList.add(brokerData); topicRouteData.setBrokerDatas(brokerDataList); List<QueueData> queueDataList = new ArrayList<QueueData>(); QueueData queueData = new QueueData(); queueData.setBrokerName("BrokerA"); queueData.setPerm(6); queueData.setReadQueueNums(3); queueData.setWriteQueueNums(4); queueData.setTopicSynFlag(0); queueDataList.add(queueData); topicRouteData.setQueueDatas(queueDataList); TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse(); assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4); }
Example #26
Source File: DefaultMQProducerTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { String producerGroupTemp = producerGroupPrefix + System.currentTimeMillis(); producer = new DefaultMQProducer(producerGroupTemp); producer.setNamesrvAddr("127.0.0.1:9876"); producer.setCompressMsgBodyOverHowmuch(16); message = new Message(topic, new byte[] {'a'}); zeroMsg = new Message(topic, new byte[] {}); bigMessage = new Message(topic, "This is a very huge message!".getBytes()); 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 #27
Source File: MQClientInstanceTest.java From DDMQ with Apache License 2.0 | 5 votes |
@Test public void testTopicRouteData2TopicPublishInfo() { TopicRouteData topicRouteData = new TopicRouteData(); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); List<BrokerData> brokerDataList = new ArrayList<BrokerData>(); BrokerData brokerData = new BrokerData(); brokerData.setBrokerName("BrokerA"); brokerData.setCluster("DefaultCluster"); HashMap<Long, String> brokerAddrs = new HashMap<Long, String>(); brokerAddrs.put(0L, "127.0.0.1:10911"); brokerData.setBrokerAddrs(brokerAddrs); brokerDataList.add(brokerData); topicRouteData.setBrokerDatas(brokerDataList); List<QueueData> queueDataList = new ArrayList<QueueData>(); QueueData queueData = new QueueData(); queueData.setBrokerName("BrokerA"); queueData.setPerm(6); queueData.setReadQueueNums(3); queueData.setWriteQueueNums(4); queueData.setTopicSynFlag(0); queueDataList.add(queueData); topicRouteData.setQueueDatas(queueDataList); TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse(); assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4); }
Example #28
Source File: MQAdminImpl.java From rocketmq with Apache License 2.0 | 5 votes |
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException { try { TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); if (topicRouteData != null) { TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); if (topicPublishInfo != null && topicPublishInfo.ok()) { return topicPublishInfo.getMessageQueueList(); } } } catch (Exception e) { throw new MQClientException("Can not find Message Queue for this topic, " + topic, e); } throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null); }
Example #29
Source File: MQClientInstanceTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Test public void testTopicRouteData2TopicPublishInfo() { TopicRouteData topicRouteData = new TopicRouteData(); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); List<BrokerData> brokerDataList = new ArrayList<BrokerData>(); BrokerData brokerData = new BrokerData(); brokerData.setBrokerName("BrokerA"); brokerData.setCluster("DefaultCluster"); HashMap<Long, String> brokerAddrs = new HashMap<Long, String>(); brokerAddrs.put(0L, "127.0.0.1:10911"); brokerData.setBrokerAddrs(brokerAddrs); brokerDataList.add(brokerData); topicRouteData.setBrokerDatas(brokerDataList); List<QueueData> queueDataList = new ArrayList<QueueData>(); QueueData queueData = new QueueData(); queueData.setBrokerName("BrokerA"); queueData.setPerm(6); queueData.setReadQueueNums(3); queueData.setWriteQueueNums(4); queueData.setTopicSynFlag(0); queueDataList.add(queueData); topicRouteData.setQueueDatas(queueDataList); TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData); assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse(); assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4); }
Example #30
Source File: ClientFuseTest.java From DeFiBus with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { DeFiBusClientConfig clientConfig = new DeFiBusClientConfig(); clientConfig.setClusterPrefix("GL"); clientConfig.setProducerGroup(producerGroup); clientConfig.setNamesrvAddr("127.0.0.1:9876"); deFiBusProducer = new DeFiBusProducer(clientConfig); deFiBusProducer.start(); msg = new Message(topic, new byte[] {'a'}); Field field = DefaultMQProducerImpl.class.getDeclaredField("mQClientFactory"); field.setAccessible(true); field.set(deFiBusProducer.getDefaultMQProducer().getDefaultMQProducerImpl(), mQClientFactory); field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl"); field.setAccessible(true); field.set(mQClientFactory, mqClientAPIImpl); deFiBusProducer.getDefaultMQProducer().getDefaultMQProducerImpl().getmQClientFactory(). registerProducer(producerGroup, deFiBusProducer.getDefaultMQProducer().getDefaultMQProducerImpl()); Exception e = new MQBrokerException(DeFiBusResponseCode.CONSUME_DIFF_SPAN_TOO_LONG, "CODE: " + DeFiBusResponseCode.CONSUME_DIFF_SPAN_TOO_LONG + " DESC: consume span too long, maybe has slow consumer, so send rejected\nFor more information, please visit the url, http://rocketmq.apache.org/docs/faq/"); when(mqClientAPIImpl.sendMessage(anyString(), anyString(), any(Message.class), any(SendMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), any(SendCallback.class), nullable(TopicPublishInfo.class), any(MQClientInstance.class), anyInt(), nullable(SendMessageContext.class), any(DefaultMQProducerImpl.class))) .thenAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); SendCallback callback = (SendCallback) args[6]; callback.onException(e); return new SendResult(); } }); }