All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.solace.spring.cloud.stream.binder.health.SolaceBinderHealthAccessor Maven / Gradle / Ivy

There is a newer version: 5.0.1
Show newest version
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;

/**
 * 

Proxy class for the Solace binder to access health components. * Always use this instead of directly using health components in Solace binder code.

*

Allows for the Solace binder to still function correctly without actuator on the classpath.

*/ 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; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy