-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #237 from SolaceProducts/stage-3.1.0
# Global Changes * Solace PubSub+ Messaging API for Java (JCSMP) upgraded to `10.21.0` * Spring Boot upgraded to `3.1.5` * Spring Cloud upgraded to `2022.0.4` # Specific Project Changes ## Solace Spring Cloud Stream Binder * Added health indicators to capture flow health * closes #145 * Added support for Solace PubSub+ partitioned queues * Fixed potential error channel name collisions
- Loading branch information
Showing
47 changed files
with
1,690 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...rc/main/java/com/solace/spring/cloud/stream/binder/health/SolaceBinderHealthAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.solace.spring.cloud.stream.binder.health; | ||
|
||
import com.solace.spring.cloud.stream.binder.health.contributors.BindingHealthContributor; | ||
import com.solace.spring.cloud.stream.binder.health.contributors.FlowsHealthContributor; | ||
import com.solace.spring.cloud.stream.binder.health.contributors.SolaceBinderHealthContributor; | ||
import com.solace.spring.cloud.stream.binder.health.handlers.SolaceFlowHealthEventHandler; | ||
import com.solace.spring.cloud.stream.binder.health.indicators.FlowHealthIndicator; | ||
import com.solace.spring.cloud.stream.binder.util.FlowReceiverContainer; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* <p>Proxy class for the Solace binder to access health components. | ||
* Always use this instead of directly using health components in Solace binder code.</p> | ||
* <p>Allows for the Solace binder to still function correctly without actuator on the classpath.</p> | ||
*/ | ||
public class SolaceBinderHealthAccessor { | ||
private final SolaceBinderHealthContributor solaceBinderHealthContributor; | ||
private static final String FLOW_ID_CONCURRENCY_IDX_PREFIX = "flow-"; | ||
|
||
public SolaceBinderHealthAccessor(SolaceBinderHealthContributor solaceBinderHealthContributor) { | ||
this.solaceBinderHealthContributor = solaceBinderHealthContributor; | ||
} | ||
|
||
public void addFlow(String bindingName, int concurrencyIdx, FlowReceiverContainer flowReceiverContainer) { | ||
FlowHealthIndicator flowHealthIndicator = new FlowHealthIndicator(); | ||
Optional.ofNullable(solaceBinderHealthContributor.getSolaceBindingsHealthContributor()) | ||
.map(b -> b.getContributor(bindingName)) | ||
.orElseGet(() -> { | ||
BindingHealthContributor newBindingHealth = new BindingHealthContributor(new FlowsHealthContributor()); | ||
solaceBinderHealthContributor.getSolaceBindingsHealthContributor() | ||
.addBindingContributor(bindingName, newBindingHealth); | ||
return newBindingHealth; | ||
}) | ||
.getFlowsHealthContributor() | ||
.addFlowContributor(createFlowIdFromConcurrencyIdx(concurrencyIdx), flowHealthIndicator); | ||
flowReceiverContainer.setEventHandler(new SolaceFlowHealthEventHandler( | ||
flowReceiverContainer.getXMLMessageMapper(), | ||
flowReceiverContainer.getId().toString(), | ||
flowHealthIndicator)); | ||
} | ||
|
||
public void removeFlow(String bindingName, int concurrencyIdx) { | ||
Optional.ofNullable(solaceBinderHealthContributor.getSolaceBindingsHealthContributor()) | ||
.map(b -> b.getContributor(bindingName)) | ||
.map(BindingHealthContributor::getFlowsHealthContributor) | ||
.ifPresent(b -> b.removeFlowContributor(createFlowIdFromConcurrencyIdx(concurrencyIdx))); | ||
} | ||
|
||
private String createFlowIdFromConcurrencyIdx(int concurrencyIdx) { | ||
return FLOW_ID_CONCURRENCY_IDX_PREFIX + concurrencyIdx; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...rc/main/java/com/solace/spring/cloud/stream/binder/health/base/SolaceHealthIndicator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.solace.spring.cloud.stream.binder.health.base; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.HealthIndicator; | ||
import org.springframework.boot.actuate.health.Status; | ||
import org.springframework.lang.Nullable; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Optional; | ||
|
||
@NoArgsConstructor | ||
public class SolaceHealthIndicator implements HealthIndicator { | ||
private static final String STATUS_RECONNECTING = "RECONNECTING"; | ||
private static final String INFO = "info"; | ||
private static final String RESPONSE_CODE = "responseCode"; | ||
@Setter(AccessLevel.PACKAGE) | ||
private volatile Health health; | ||
private static final Log logger = LogFactory.getLog(SolaceHealthIndicator.class); | ||
|
||
private static void logDebugStatus(String status) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug(String.format("Solace connection/flow status is %s", status)); | ||
} | ||
} | ||
protected void healthUp() { | ||
health = Health.up().build(); | ||
logDebugStatus(String.valueOf(Status.UP)); | ||
} | ||
protected <T> void healthReconnecting(@Nullable T eventArgs) { | ||
health = addEventDetails(Health.status(STATUS_RECONNECTING), eventArgs).build(); | ||
logDebugStatus(STATUS_RECONNECTING); | ||
} | ||
|
||
protected <T> void healthDown(@Nullable T eventArgs) { | ||
health = addEventDetails(Health.down(), eventArgs).build(); | ||
logDebugStatus(String.valueOf(Status.DOWN)); | ||
} | ||
|
||
public <T> Health.Builder addEventDetails(Health.Builder builder, @Nullable T eventArgs) { | ||
if (eventArgs == null) { | ||
return builder; | ||
} | ||
|
||
try { | ||
Optional.ofNullable(eventArgs.getClass().getMethod("getException").invoke(eventArgs)) | ||
.ifPresent(ex -> builder.withException((Throwable) ex)); | ||
Optional.of(eventArgs.getClass().getMethod("getResponseCode").invoke(eventArgs)) | ||
.filter(c -> ((int) c) != 0) | ||
.ifPresent(c -> builder.withDetail(RESPONSE_CODE, c)); | ||
Optional.ofNullable(eventArgs.getClass().getMethod("getInfo").invoke(eventArgs)) | ||
.filter(t -> StringUtils.isNotBlank(String.valueOf(t))) | ||
.ifPresent(info -> builder.withDetail(INFO, info)); | ||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return builder; | ||
} | ||
|
||
@Override | ||
public Health health() { | ||
return health; | ||
} | ||
} |
Oops, something went wrong.