use of org.apache.rocketmq.client.exception.MQBrokerException in project rocketmq by apache.
the class BrokerOuterAPI method getAllSubscriptionGroupConfig.
public SubscriptionGroupWrapper getAllSubscriptionGroupConfig(final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
assert response != null;
switch(response.getCode()) {
case ResponseCode.SUCCESS:
{
return SubscriptionGroupWrapper.decode(response.getBody(), SubscriptionGroupWrapper.class);
}
default:
break;
}
throw new MQBrokerException(response.getCode(), response.getRemark());
}
use of org.apache.rocketmq.client.exception.MQBrokerException in project rocketmq by apache.
the class BrokerOuterAPI method getAllConsumerOffset.
public ConsumerOffsetSerializeWrapper getAllConsumerOffset(final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_CONSUMER_OFFSET, null);
RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
assert response != null;
switch(response.getCode()) {
case ResponseCode.SUCCESS:
{
return ConsumerOffsetSerializeWrapper.decode(response.getBody(), ConsumerOffsetSerializeWrapper.class);
}
default:
break;
}
throw new MQBrokerException(response.getCode(), response.getRemark());
}
use of org.apache.rocketmq.client.exception.MQBrokerException in project rocketmq by apache.
the class QueryMsgByUniqueKeySubCommand method queryById.
public static void queryById(final DefaultMQAdminExt admin, final String topic, final String msgId) throws MQClientException, RemotingException, MQBrokerException, InterruptedException, IOException {
MessageExt msg = admin.viewMessage(topic, msgId);
String bodyTmpFilePath = createBodyFile(msg);
System.out.printf("%-20s %s%n", "Topic:", msg.getTopic());
System.out.printf("%-20s %s%n", "Tags:", "[" + msg.getTags() + "]");
System.out.printf("%-20s %s%n", "Keys:", "[" + msg.getKeys() + "]");
System.out.printf("%-20s %d%n", "Queue ID:", msg.getQueueId());
System.out.printf("%-20s %d%n", "Queue Offset:", msg.getQueueOffset());
System.out.printf("%-20s %d%n", "CommitLog Offset:", msg.getCommitLogOffset());
System.out.printf("%-20s %d%n", "Reconsume Times:", msg.getReconsumeTimes());
System.out.printf("%-20s %s%n", "Born Timestamp:", UtilAll.timeMillisToHumanString2(msg.getBornTimestamp()));
System.out.printf("%-20s %s%n", "Store Timestamp:", UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp()));
System.out.printf("%-20s %s%n", "Born Host:", RemotingHelper.parseSocketAddressAddr(msg.getBornHost()));
System.out.printf("%-20s %s%n", "Store Host:", RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()));
System.out.printf("%-20s %d%n", "System Flag:", msg.getSysFlag());
System.out.printf("%-20s %s%n", "Properties:", msg.getProperties() != null ? msg.getProperties().toString() : "");
System.out.printf("%-20s %s%n", "Message Body Path:", bodyTmpFilePath);
try {
List<MessageTrack> mtdList = admin.messageTrackDetail(msg);
if (mtdList.isEmpty()) {
System.out.printf("%n%nWARN: No Consumer");
} else {
System.out.printf("%n%n");
for (MessageTrack mt : mtdList) {
System.out.printf("%s", mt);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.rocketmq.client.exception.MQBrokerException in project rocketmq by apache.
the class DefaultMQAdminExtImpl method messageTrackDetail.
@Override
public List<MessageTrack> messageTrackDetail(MessageExt msg) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
List<MessageTrack> result = new ArrayList<MessageTrack>();
GroupList groupList = this.queryTopicConsumeByWho(msg.getTopic());
for (String group : groupList.getGroupList()) {
MessageTrack mt = new MessageTrack();
mt.setConsumerGroup(group);
mt.setTrackType(TrackType.UNKNOWN);
ConsumerConnection cc = null;
try {
cc = this.examineConsumerConnectionInfo(group);
} catch (MQBrokerException e) {
if (ResponseCode.CONSUMER_NOT_ONLINE == e.getResponseCode()) {
mt.setTrackType(TrackType.NOT_ONLINE);
}
mt.setExceptionDesc("CODE:" + e.getResponseCode() + " DESC:" + e.getErrorMessage());
result.add(mt);
continue;
} catch (Exception e) {
mt.setExceptionDesc(RemotingHelper.exceptionSimpleDesc(e));
result.add(mt);
continue;
}
switch(cc.getConsumeType()) {
case CONSUME_ACTIVELY:
mt.setTrackType(TrackType.PULL);
break;
case CONSUME_PASSIVELY:
boolean ifConsumed = false;
try {
ifConsumed = this.consumed(msg, group);
} catch (MQClientException e) {
if (ResponseCode.CONSUMER_NOT_ONLINE == e.getResponseCode()) {
mt.setTrackType(TrackType.NOT_ONLINE);
}
mt.setExceptionDesc("CODE:" + e.getResponseCode() + " DESC:" + e.getErrorMessage());
result.add(mt);
continue;
} catch (MQBrokerException e) {
if (ResponseCode.CONSUMER_NOT_ONLINE == e.getResponseCode()) {
mt.setTrackType(TrackType.NOT_ONLINE);
}
mt.setExceptionDesc("CODE:" + e.getResponseCode() + " DESC:" + e.getErrorMessage());
result.add(mt);
continue;
} catch (Exception e) {
mt.setExceptionDesc(RemotingHelper.exceptionSimpleDesc(e));
result.add(mt);
continue;
}
if (ifConsumed) {
mt.setTrackType(TrackType.CONSUMED);
Iterator<Entry<String, SubscriptionData>> it = cc.getSubscriptionTable().entrySet().iterator();
while (it.hasNext()) {
Entry<String, SubscriptionData> next = it.next();
if (next.getKey().equals(msg.getTopic())) {
if (next.getValue().getTagsSet().contains(msg.getTags()) || next.getValue().getTagsSet().contains("*") || next.getValue().getTagsSet().isEmpty()) {
} else {
mt.setTrackType(TrackType.CONSUMED_BUT_FILTERED);
}
}
}
} else {
mt.setTrackType(TrackType.NOT_CONSUME_YET);
}
break;
default:
break;
}
result.add(mt);
}
return result;
}
use of org.apache.rocketmq.client.exception.MQBrokerException in project rocketmq-externals by apache.
the class RocketMQSourceTest method testEvent.
@Test
public void testEvent() throws EventDeliveryException, MQBrokerException, MQClientException, InterruptedException, UnsupportedEncodingException {
// publish test message
DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
producer.setNamesrvAddr(nameServer);
String sendMsg = "\"Hello Flume\"" + "," + DateFormatUtils.format(new Date(), "yyyy-MM-DD hh:mm:ss");
try {
producer.start();
Message msg = new Message(TOPIC_DEFAULT, tag, sendMsg.getBytes("UTF-8"));
SendResult sendResult = producer.send(msg);
log.info("publish message : {}, sendResult:{}", sendMsg, sendResult);
} catch (Exception e) {
throw new MQClientException("Failed to publish messages", e);
} finally {
producer.shutdown();
}
// start source
Context context = new Context();
context.put(NAME_SERVER_CONFIG, nameServer);
context.put(TAG_CONFIG, tag);
Channel channel = new MemoryChannel();
Configurables.configure(channel, context);
List<Channel> channels = new ArrayList<>();
channels.add(channel);
ChannelSelector channelSelector = new ReplicatingChannelSelector();
channelSelector.setChannels(channels);
ChannelProcessor channelProcessor = new ChannelProcessor(channelSelector);
RocketMQSource source = new RocketMQSource();
source.setChannelProcessor(channelProcessor);
Configurables.configure(source, context);
source.start();
PollableSource.Status status = source.process();
if (status == PollableSource.Status.BACKOFF) {
fail("Error");
}
/*
wait for processQueueTable init
*/
Thread.sleep(1000);
source.stop();
/*
mock flume sink
*/
Transaction transaction = channel.getTransaction();
transaction.begin();
Event event = channel.take();
if (event == null) {
transaction.commit();
fail("Error");
}
byte[] body = event.getBody();
String receiveMsg = new String(body, "UTF-8");
log.info("receive message : {}", receiveMsg);
assertEquals(sendMsg, receiveMsg);
}
Aggregations