Axon / Consul

Hi all

I switched to the new 3.1 version of Axon Framework and I’m trying to integrate my Spring Boot Application with Consul. My application starts as a service in a Docker Swarm.

The documentation states that you have to add the following properties:

`

whether to fall back to http when no meta-data is available

axon.distributed.spring-cloud.fallback-to-http-get=true

the URL on which to publish local data and retrieve from other nodes.

axon.distributed.spring-cloud.fallback-url=/message-routing-information
`

in order to activate the new backup Spring Cloud Command Router.

What I don’t understand is who is in charge to provide the fallback url. Is it an endpoint that I have to implement or is it made available directly by Axon?

The other strange thing I can see from the log is that my application tries to contact that endpoint (/message-routing-information) performing a HTTP request to the consul node, using port 8300. Why it is using this port?

Thank you very much

Hi Franco,

the two properties you describe are actually the default settings. The first indicates whether you want to use an HTTP call as a backup way to retrieve Axon meta-data from a node. Some discovery mechanisms don’t support meta data. Using HTTP as fallback will ensure it will always work.

Axon will register a servlet/handler on the given URL (relative to the root), but will also use it to invoke the URL on other nodes. The URL is assembled based on information it retrieves from consul. So if it is using post 8300, it must be because your application registered itself with Consul as being published on that port.

Hope this clarifies things.
Cheers,

Allard

Thank you Allard.

Now it all seems to work, my events are stored correctly using two application nodes in the swarm, but in the log I’m always seeing this kind of error.

org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://172.29.20.4:8300/message-routing-information": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)

from SpringCloudHttpBackupCommandRouter.requestMessageRoutingInformation method.

I think that the problem is that SpringCloudCommandRouter must be configured with a specific serviceInstanceFilter. I’ll try to explain. When Consul returns the list of service instances, the payload includes also the information about the consul node itself (!), and so Axon tries to contact also Consul using the fallback url.

In order to avoid this, I think that I have to provide an instance of SpringCloudCommandRouter with a filter that excludes all instances with a name different than the application name.

I’ll let you know if this works.

Hi Franco,

Axon will indeed send all the nodes it receives information about a GET request on that URL. However, if it gets an error like this, it will (at least: should) not call that node anymore, as it will assume it’s not an Axon node.
Implementing a ServiceInstanceFilter will allow you to specify which service instances should be considered Axon applications. If you don’t expect different Axon applications to communicate with eachother, then filtering on name should suffice. You could also consider registering certain “tags” for these applications and using those to filter.

Cheers,

Allard