|
|
|
@ -62,14 +62,14 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport {
|
|
|
|
|
|
|
|
|
|
private ConsumerInstrumentation consumerInstrumentation;
|
|
|
|
|
|
|
|
|
|
private InstrumentationManager instrumentationManager;
|
|
|
|
|
|
|
|
|
|
private final ExtendedConsumerProperties<RocketMQConsumerProperties> consumerProperties;
|
|
|
|
|
|
|
|
|
|
private final String destination;
|
|
|
|
|
|
|
|
|
|
private final String group;
|
|
|
|
|
|
|
|
|
|
private final InstrumentationManager instrumentationManager;
|
|
|
|
|
|
|
|
|
|
private final ConsumersManager consumersManager;
|
|
|
|
|
|
|
|
|
|
private RetryTemplate retryTemplate;
|
|
|
|
@ -89,21 +89,20 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void doStart() {
|
|
|
|
|
if (!consumerProperties.getExtension().getEnabled()) {
|
|
|
|
|
if (consumerProperties == null
|
|
|
|
|
|| !consumerProperties.getExtension().getEnabled()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String tags = consumerProperties == null ? null
|
|
|
|
|
: consumerProperties.getExtension().getTags();
|
|
|
|
|
Boolean isOrderly = consumerProperties == null ? false
|
|
|
|
|
: consumerProperties.getExtension().getOrderly();
|
|
|
|
|
String tags = consumerProperties.getExtension().getTags();
|
|
|
|
|
Boolean isOrderly = consumerProperties.getExtension().getOrderly();
|
|
|
|
|
|
|
|
|
|
DefaultMQPushConsumer consumer = consumersManager.getOrCreateConsumer(group,
|
|
|
|
|
destination, consumerProperties);
|
|
|
|
|
|
|
|
|
|
final CloudStreamMessageListener listener = isOrderly
|
|
|
|
|
? new CloudStreamMessageListenerOrderly(instrumentationManager)
|
|
|
|
|
: new CloudStreamMessageListenerConcurrently(instrumentationManager);
|
|
|
|
|
? new CloudStreamMessageListenerOrderly()
|
|
|
|
|
: new CloudStreamMessageListenerConcurrently();
|
|
|
|
|
|
|
|
|
|
if (retryTemplate != null) {
|
|
|
|
|
retryTemplate.registerListener(listener);
|
|
|
|
@ -116,9 +115,11 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
consumerInstrumentation = instrumentationManager
|
|
|
|
|
.getConsumerInstrumentation(destination);
|
|
|
|
|
instrumentationManager.addHealthInstrumentation(consumerInstrumentation);
|
|
|
|
|
if (instrumentationManager != null) {
|
|
|
|
|
consumerInstrumentation = instrumentationManager
|
|
|
|
|
.getConsumerInstrumentation(destination);
|
|
|
|
|
instrumentationManager.addHealthInstrumentation(consumerInstrumentation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (!StringUtils.isEmpty(consumerProperties.getExtension().getSql())) {
|
|
|
|
@ -129,10 +130,14 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport {
|
|
|
|
|
consumer.subscribe(destination,
|
|
|
|
|
org.apache.commons.lang3.StringUtils.join(tagsSet, " || "));
|
|
|
|
|
}
|
|
|
|
|
consumerInstrumentation.markStartedSuccessfully();
|
|
|
|
|
if (consumerInstrumentation != null) {
|
|
|
|
|
consumerInstrumentation.markStartedSuccessfully();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (MQClientException e) {
|
|
|
|
|
consumerInstrumentation.markStartFailed(e);
|
|
|
|
|
if (consumerInstrumentation != null) {
|
|
|
|
|
consumerInstrumentation.markStartFailed(e);
|
|
|
|
|
}
|
|
|
|
|
logger.error("RocketMQ Consumer hasn't been subscribed. Caused by "
|
|
|
|
|
+ e.getErrorMessage(), e);
|
|
|
|
|
throw new RuntimeException("RocketMQ Consumer hasn't been subscribed.", e);
|
|
|
|
@ -166,19 +171,12 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport {
|
|
|
|
|
|
|
|
|
|
protected class CloudStreamMessageListener implements MessageListener, RetryListener {
|
|
|
|
|
|
|
|
|
|
private final InstrumentationManager instrumentationManager;
|
|
|
|
|
|
|
|
|
|
CloudStreamMessageListener(InstrumentationManager instrumentationManager) {
|
|
|
|
|
this.instrumentationManager = instrumentationManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Acknowledgement consumeMessage(final List<MessageExt> msgs) {
|
|
|
|
|
boolean enableRetry = RocketMQInboundChannelAdapter.this.retryTemplate != null;
|
|
|
|
|
try {
|
|
|
|
|
if (enableRetry) {
|
|
|
|
|
return RocketMQInboundChannelAdapter.this.retryTemplate.execute(
|
|
|
|
|
// (RetryCallback<Acknowledgement, Exception>)
|
|
|
|
|
new RetryCallback<Acknowledgement, Exception>() {
|
|
|
|
|
return RocketMQInboundChannelAdapter.this.retryTemplate
|
|
|
|
|
.execute(new RetryCallback<Acknowledgement, Exception>() {
|
|
|
|
|
@Override
|
|
|
|
|
public Acknowledgement doWithRetry(RetryContext context)
|
|
|
|
|
throws Exception {
|
|
|
|
@ -203,10 +201,12 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Acknowledgement result = doSendMsgs(msgs, null);
|
|
|
|
|
instrumentationManager
|
|
|
|
|
.getConsumerInstrumentation(
|
|
|
|
|
RocketMQInboundChannelAdapter.this.destination)
|
|
|
|
|
.markConsumed();
|
|
|
|
|
if (RocketMQInboundChannelAdapter.this.instrumentationManager != null) {
|
|
|
|
|
RocketMQInboundChannelAdapter.this.instrumentationManager
|
|
|
|
|
.getConsumerInstrumentation(
|
|
|
|
|
RocketMQInboundChannelAdapter.this.destination)
|
|
|
|
|
.markConsumed();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -214,10 +214,12 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport {
|
|
|
|
|
logger.error(
|
|
|
|
|
"RocketMQ Message hasn't been processed successfully. Caused by ",
|
|
|
|
|
e);
|
|
|
|
|
instrumentationManager
|
|
|
|
|
.getConsumerInstrumentation(
|
|
|
|
|
RocketMQInboundChannelAdapter.this.destination)
|
|
|
|
|
.markConsumedFailure();
|
|
|
|
|
if (RocketMQInboundChannelAdapter.this.instrumentationManager != null) {
|
|
|
|
|
RocketMQInboundChannelAdapter.this.instrumentationManager
|
|
|
|
|
.getConsumerInstrumentation(
|
|
|
|
|
RocketMQInboundChannelAdapter.this.destination)
|
|
|
|
|
.markConsumedFailure();
|
|
|
|
|
}
|
|
|
|
|
throw new RuntimeException(
|
|
|
|
|
"RocketMQ Message hasn't been processed successfully. Caused by ",
|
|
|
|
|
e);
|
|
|
|
@ -254,14 +256,17 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport {
|
|
|
|
|
@Override
|
|
|
|
|
public <T, E extends Throwable> void close(RetryContext context,
|
|
|
|
|
RetryCallback<T, E> callback, Throwable throwable) {
|
|
|
|
|
if (RocketMQInboundChannelAdapter.this.instrumentationManager == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (throwable != null) {
|
|
|
|
|
instrumentationManager
|
|
|
|
|
RocketMQInboundChannelAdapter.this.instrumentationManager
|
|
|
|
|
.getConsumerInstrumentation(
|
|
|
|
|
RocketMQInboundChannelAdapter.this.destination)
|
|
|
|
|
.markConsumedFailure();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
instrumentationManager
|
|
|
|
|
RocketMQInboundChannelAdapter.this.instrumentationManager
|
|
|
|
|
.getConsumerInstrumentation(
|
|
|
|
|
RocketMQInboundChannelAdapter.this.destination)
|
|
|
|
|
.markConsumed();
|
|
|
|
@ -277,11 +282,6 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport {
|
|
|
|
|
protected class CloudStreamMessageListenerConcurrently
|
|
|
|
|
extends CloudStreamMessageListener implements MessageListenerConcurrently {
|
|
|
|
|
|
|
|
|
|
public CloudStreamMessageListenerConcurrently(
|
|
|
|
|
InstrumentationManager instrumentationManager) {
|
|
|
|
|
super(instrumentationManager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ConsumeConcurrentlyStatus consumeMessage(final List<MessageExt> msgs,
|
|
|
|
|
ConsumeConcurrentlyContext context) {
|
|
|
|
@ -295,11 +295,6 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport {
|
|
|
|
|
protected class CloudStreamMessageListenerOrderly extends CloudStreamMessageListener
|
|
|
|
|
implements MessageListenerOrderly {
|
|
|
|
|
|
|
|
|
|
public CloudStreamMessageListenerOrderly(
|
|
|
|
|
InstrumentationManager instrumentationManager) {
|
|
|
|
|
super(instrumentationManager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
|
|
|
|
|
ConsumeOrderlyContext context) {
|
|
|
|
|