Adds minimal logging for bus events.

fixes gh-217
This commit is contained in:
Spencer Gibb
2020-03-10 16:18:17 -04:00
parent aff31fed9a
commit d5985ac16d
4 changed files with 49 additions and 1 deletions

View File

@@ -18,6 +18,9 @@ package org.springframework.cloud.bus;
import javax.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
@@ -69,6 +72,8 @@ import org.springframework.util.PathMatcher;
// so actuator endpoints have needed dependencies
public class BusAutoConfiguration implements ApplicationEventPublisherAware {
private static final Log log = LogFactory.getLog(BusAutoConfiguration.class);
/**
* Name of the Bus path matcher.
*/
@@ -140,6 +145,9 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
public void acceptLocal(RemoteApplicationEvent event) {
if (this.serviceMatcher.isFromSelf(event)
&& !(event instanceof AckRemoteApplicationEvent)) {
if (log.isDebugEnabled()) {
log.debug("Sending remote event on bus: " + event);
}
this.cloudBusOutboundChannel.send(MessageBuilder.withPayload(event).build());
}
}
@@ -154,6 +162,11 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
// If it's an ACK we are finished processing at this point
return;
}
if (log.isDebugEnabled()) {
log.debug("Received remote event from bus: " + event);
}
if (this.serviceMatcher.isForSelf(event)
&& this.applicationEventPublisher != null) {
if (!this.serviceMatcher.isFromSelf(event)) {

View File

@@ -18,6 +18,8 @@ package org.springframework.cloud.bus.event;
import java.util.Map;
import org.springframework.core.style.ToStringCreator;
/**
* @author Spencer Gibb
*/
@@ -73,4 +75,13 @@ public class EnvironmentChangeRemoteApplicationEvent extends RemoteApplicationEv
return true;
}
@Override
public String toString() {
return new ToStringCreator(this).append("id", getId())
.append("originService", getOriginService())
.append("destinationService", getDestinationService())
.append("values", values).toString();
}
}

View File

@@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.style.ToStringCreator;
import org.springframework.util.StringUtils;
/**
@@ -134,4 +135,12 @@ public abstract class RemoteApplicationEvent extends ApplicationEvent {
return true;
}
@Override
public String toString() {
return new ToStringCreator(this).append("id", id)
.append("originService", originService)
.append("destinationService", destinationService).toString();
}
}

View File

@@ -16,6 +16,8 @@
package org.springframework.cloud.bus.event;
import org.springframework.core.style.ToStringCreator;
/**
* @author Stefan Pfeiffer
*/
@@ -49,7 +51,20 @@ public class UnknownRemoteApplicationEvent extends RemoteApplicationEvent {
}
public String getPayloadAsString() {
return new String(this.payload);
if (this.payload != null) {
return new String(this.payload);
}
return null;
}
@Override
public String toString() {
return new ToStringCreator(this).append("id", getId())
.append("originService", getOriginService())
.append("destinationService", getDestinationService())
.append("typeInfo", typeInfo).append("payload", getPayloadAsString())
.toString();
}
}