Search in sources :

Example 1 with Connection

use of org.apache.rocketmq.common.protocol.body.Connection in project rocketmq-externals by apache.

the class ConsumerServiceImpl method getClientConnection.

private Map<MessageQueue, String> getClientConnection(String groupName) {
    Map<MessageQueue, String> results = Maps.newHashMap();
    try {
        ConsumerConnection consumerConnection = mqAdminExt.examineConsumerConnectionInfo(groupName);
        for (Connection connection : consumerConnection.getConnectionSet()) {
            String clinetId = connection.getClientId();
            ConsumerRunningInfo consumerRunningInfo = mqAdminExt.getConsumerRunningInfo(groupName, clinetId, false);
            for (MessageQueue messageQueue : consumerRunningInfo.getMqTable().keySet()) {
                // results.put(messageQueue, clinetId + " " + connection.getClientAddr());
                results.put(messageQueue, clinetId);
            }
        }
    } catch (Exception err) {
        logger.error("op=getClientConnection_error", err);
    }
    return results;
}
Also used : MessageQueue(org.apache.rocketmq.common.message.MessageQueue) Connection(org.apache.rocketmq.common.protocol.body.Connection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ConsumerRunningInfo(org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 2 with Connection

use of org.apache.rocketmq.common.protocol.body.Connection in project rocketmq-externals by apache.

the class ConsumerServiceImplTest method getConsumerConnection.

@Test
public void getConsumerConnection() throws Exception {
    ConsumerConnection consumerConnection = new RetryTempLate<ConsumerConnection>() {

        @Override
        protected ConsumerConnection process() throws Exception {
            return consumerService.getConsumerConnection(TEST_CONSUMER_GROUP);
        }
    }.execute(10, 2000);
    Assert.assertNotNull(consumerConnection);
    Assert.assertTrue(CollectionUtils.isNotEmpty(consumerConnection.getConnectionSet()));
    Assert.assertTrue(Lists.transform(Lists.newArrayList(consumerConnection.getConnectionSet()), new Function<Connection, String>() {

        @Override
        public String apply(Connection input) {
            return input.getClientAddr().split(":")[0];
        }
    }).contains(TestConstant.BROKER_IP));
}
Also used : Connection(org.apache.rocketmq.common.protocol.body.Connection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Connection

use of org.apache.rocketmq.common.protocol.body.Connection in project rocketmq-externals by apache.

the class ProducerServiceImplTest method getProducerConnection.

@Test
public void getProducerConnection() throws Exception {
    ProducerConnection producerConnection = new RetryTempLate<ProducerConnection>() {

        @Override
        protected ProducerConnection process() throws Exception {
            return producerService.getProducerConnection(TEST_PRODUCER_GROUP, TEST_CONSOLE_TOPIC);
        }
    }.execute(10, 1000);
    Assert.assertNotNull(producerConnection);
    Assert.assertTrue(Lists.transform(Lists.newArrayList(producerConnection.getConnectionSet()), new Function<Connection, String>() {

        @Override
        public String apply(Connection input) {
            return input.getClientAddr().split(":")[0];
        }
    }).contains(TestConstant.LOCAL_HOST));
}
Also used : ProducerConnection(org.apache.rocketmq.common.protocol.body.ProducerConnection) Connection(org.apache.rocketmq.common.protocol.body.Connection) ProducerConnection(org.apache.rocketmq.common.protocol.body.ProducerConnection) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Connection (org.apache.rocketmq.common.protocol.body.Connection)3 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)1 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)1 ConsumerRunningInfo (org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo)1 ProducerConnection (org.apache.rocketmq.common.protocol.body.ProducerConnection)1