axon:
distributed:
spring-cloud:
fallback-to-http-get: true
enabled: true
Caused by: org.axonframework.commandhandling.NoHandlerForCommandException: No node known to accept [com.myapp.commands.MyCommand]
@Bean public CommandRouter springCloudHttpBackupCommandRouter( DiscoveryClient discoveryClient, RestTemplate restTemplate, Registration localServiceInstance, @Value("${axon.distributed.spring-cloud.fallback-url}") String messageRoutingInformationEndpoint) { return SpringCloudHttpBackupCommandRouter.builder() .discoveryClient(discoveryClient) .routingStrategy(new AnnotationRoutingStrategy()) .restTemplate(restTemplate) .localServiceInstance(localServiceInstance) .messageRoutingInformationEndpoint(messageRoutingInformationEndpoint) .build();
public class RestSecurityInterceptor implements ClientHttpRequestInterceptor {
String authToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE1OTUxMzM3ODcsImV4cCI6MTYyNjY2OTc4NywiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsInJvbGVzIjpbIkFOT05ZTU9VUyJdLCJhdXRoZW50aWNhdGVkIjp0cnVlfQ.iHODq9RKtosejJgh6RDyKzn18a_OuWJTKGA1RYxPQ0Q";
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
HttpHeaders headers = request.getHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.set("User-Agent", "resttemplate"); //Set the header for each request
headers.set("Authorization", "Bearer "+authToken );
return execution.execute(request, body);
}
}
@Bean
public CommandRouter springCloudHttpBackupCommandRouter(
DiscoveryClient discoveryClient,
RestTemplate restTemplate,
Registration localServiceInstance,
@Value("${axon.distributed.spring-cloud.fallback-url}")
String messageRoutingInformationEndpoint) {
restTemplate.setInterceptors(Collections.singletonList(new RestSecurityInterceptor()));
return SpringCloudHttpBackupCommandRouter.builder()
.discoveryClient(discoveryClient)
.routingStrategy(new AnnotationRoutingStrategy())
.enforceHttpDiscovery()
.restTemplate(restTemplate)
.localServiceInstance(localServiceInstance)
.messageRoutingInformationEndpoint(messageRoutingInformationEndpoint)
.build();
}
server:
port: 8081
eureka:
instance:
lease-renewal-interval-in-seconds: 1
lease-expiration-duration-in-seconds: 2
health-check-url: http://localhost:8081/actuator/health/
prefer-ip-address: true
status-page-url: http://localhost:8081/actuator/info/
ip-address: 127.0.0.1
hostname: localhost
instance-id: localhost:${server.port}
client:
serviceUrl:
defaultZone: http://eureka:123456@localhost:8761/eureka/
healthcheck:
enabled: true
enabled: true
use-dns-for-fetching-service-urls: false
on-demand-update-status-change: true
If you are using SpringBoot, there is mo need to manually configure anything. Let SpringBoot handle all the auto configuration for you.
Based on my previous posts, you WILL still need to provide a Bean for SpringCloudHttpBackupCommandRouter as shown in my post.
Also, make sure that when you Axon services startup, they are able to successfully connect to your Eureka instance. You can verify this from the Eureka console at http://localhost:8761 (or wherever your Eureka server is running).
Try posting a GET REST api call from a REST client to the URL shown in Eureka console for your service e.g. http://192.xx.xx.xx:8080/message-routing-information. If you get a successful response, then you should be OK. If not, then you need to find out why you are not able to hit your Axon service at the above URL (could be because of network issues). Use the Eureka client configuration I shared earlier as a starting point to help resolve these issues.
Sorry, but without knowing your specific setup, I can only help you in general terms.