INT-1815 added logging for all SubscribableChannels as well as EventDrovenConsumer handler when it subscribes to a Channel
This commit is contained in:
@@ -39,16 +39,13 @@ public abstract class AbstractSubscribableChannel extends AbstractMessageChannel
|
||||
|
||||
public boolean subscribe(MessageHandler handler) {
|
||||
MessageDispatcher dispatcher = this.getRequiredDispatcher();
|
||||
if (dispatcher instanceof UnicastingDispatcher){
|
||||
boolean added = dispatcher.addHandler(handler);
|
||||
if (added){
|
||||
int counter = handlers.incrementAndGet();
|
||||
if (counter > 1){
|
||||
String message = "Point-to-Point channel '" + this.getComponentName() + "' has more then 1 subscriber - (" + counter + "). " +
|
||||
"If load balancing strategy is provided, messages will be dispatched following its rules.";
|
||||
this.logger.info(message);
|
||||
}
|
||||
logger.info("Channel '" + this.getComponentName() + "' has " + counter + " subscriber(s). ");
|
||||
}
|
||||
|
||||
return dispatcher.addHandler(handler);
|
||||
return added;
|
||||
}
|
||||
|
||||
public boolean unsubscribe(MessageHandler handle) {
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
|
||||
package org.springframework.integration.endpoint;
|
||||
|
||||
import org.springframework.integration.channel.AbstractSubscribableChannel;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.SubscribableChannel;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Message Endpoint that connects any {@link MessageHandler} implementation to a {@link SubscribableChannel}.
|
||||
@@ -44,6 +47,16 @@ public class EventDrivenConsumer extends AbstractEndpoint {
|
||||
|
||||
@Override
|
||||
protected void doStart() {
|
||||
if (this.handler instanceof IntegrationObjectSupport){
|
||||
String channelName = ((AbstractSubscribableChannel)this.inputChannel).getComponentName();
|
||||
String componentType = ((IntegrationObjectSupport)this.handler).getComponentType();
|
||||
componentType = StringUtils.hasText(componentType) ? componentType : "";
|
||||
String componentName = ((IntegrationObjectSupport)this).getComponentName();
|
||||
componentName = (StringUtils.hasText(componentName) && componentName.contains("#")) ? "" : ":" + componentName;
|
||||
|
||||
logger.info("Adding {" + componentType + componentName + "} as a subscriber to the '" + channelName + "' channel");
|
||||
}
|
||||
|
||||
this.inputChannel.subscribe(this.handler);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,9 +54,8 @@ public class P2pChannelTests {
|
||||
});
|
||||
|
||||
channel.subscribe(mock(MessageHandler.class));
|
||||
verify(logger, times(0)).info(Mockito.anyString());
|
||||
channel.subscribe(mock(MessageHandler.class));
|
||||
verify(logger, times(1)).info(Mockito.anyString());
|
||||
verify(logger, times(2)).info(Mockito.anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,9 +75,8 @@ public class P2pChannelTests {
|
||||
}
|
||||
});
|
||||
channel.subscribe(mock(MessageHandler.class));
|
||||
verify(logger, times(0)).info(Mockito.anyString());
|
||||
channel.subscribe(mock(MessageHandler.class));
|
||||
verify(logger, times(1)).info(Mockito.anyString());
|
||||
verify(logger, times(2)).info(Mockito.anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,8 +96,7 @@ public class P2pChannelTests {
|
||||
}
|
||||
});
|
||||
channel.subscribe(mock(MessageHandler.class));
|
||||
verify(logger, times(0)).info(Mockito.anyString());
|
||||
channel.subscribe(mock(MessageHandler.class));
|
||||
verify(logger, times(0)).info(Mockito.anyString());
|
||||
verify(logger, times(2)).info(Mockito.anyString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user