Axon Distributed command bus + Spring Boot with Spring cloud + Kubernetes not working.

Hello,

Our requirement is to deploy code on Google Cloud platform (using Kubernetes)
We are trying to move from Simple Command bus to Axon Distributed Command bus to run our code in clustered environment.

We have made changes as per the reference document provided :https://github.com/AxonIQ/reference-guide/blob/master/extensions/spring-cloud.md

In Spring Boot Application class we have annotated with EnableDiscoveryClient.

@EnableDiscoveryClient

Maven dependency added :

<!-- https://mvnrepository.com/artifact/org.axonframework.extensions.springcloud/axon-distributed-commandbus-springcloud -->
<dependency>
   <groupId>org.axonframework.extensions.springcloud</groupId>
   <artifactId>axon-distributed-commandbus-springcloud</artifactId>
   <version>4.0-RC1</version>
   <exclusions>
      <exclusion>
         <groupId>org.axonframework</groupId>
         <artifactId>axon-core</artifactId>
      </exclusion>
   </exclusions>
</dependency>

Error getting :
Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘commandGateway’ defined in class path resource [org/axonframework/springboot/autoconfig/AxonAutoConfiguration.class]: Unsatisfied dependency expressed through method ‘commandGateway’ parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘springCloudDistributedCommandBus’ defined in class path resource [se/ikea/iops/config/SpringCloudAxonConfig.class]: Unsatisfied dependency expressed through method ‘springCloudDistributedCommandBus’ parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘springCloudCommandRouter’ defined in class path resource [se/ikea/iops/config/SpringCloudAxonConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.axonframework.commandhandling.distributed.CommandRouter]: Factory method ‘springCloudCommandRouter’ threw exception; nested exception is org.axonframework.common.AxonConfigurationException: The Registration is a hard requirement and should be provided"

Can any one help us to resolve this issue?

Some sample code with Axon Distributed command bus + Spring Boot with Spring cloud + Kubernetes would be much appreciated

Thanks
Aniwesh

It seems there is an error in your SpringCloudAxonConfig class, where you create a router, but do not specify the “Registration” (which is a Spring Cloud Discovery object representing the local node). You should be able to autowire this instance in the method where you define the SpringCloudCommandRouter.

There is an example we have built together with Pivotal that uses Spring Cloud Discovery. It runs on PCF instead of Kubernetes, but from a configuration perspective, that doesn’t change anything.
You can find the project here: https://axontrader.cfapps.io/
Information: https://github.com/pivotalsoftware/ESarch/wiki/Axon-Trader-Reference-Documentation
Source code: https://github.com/pivotalsoftware/ESarch

Kind regards,

Sorry for late response.
Thank you Allard for sharing the sample example.

I am trying to run the ESarch application locally but got error as it’s trying to connect to RabbitMQ. Is it necessary to configure the rabbitmq for
axon distributed command + spring cloud + kubernetes.

In ESarch found code, but didn’t find any code related to create DistributedCommandBus.

@Autowired
public void configure(@Qualifier("localSegment") CommandBus commandBus) {
    commandBus.registerHandlerInterceptor(new LoggingInterceptor<>());
}

Error while running ESarch app:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘amqpConfiguration’: Injection of autowired dependencies failed; nested exception is org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:379) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at io.pivotal.refarch.cqrs.trader.app.TraderApplication.main(TraderApplication.java:16) [classes/:na]
Caused by: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1771) ~[spring-rabbit-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1752) ~[spring-rabbit-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.amqp.rabbit.core.RabbitAdmin.declareExchange(RabbitAdmin.java:196) ~[spring-rabbit-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at io.pivotal.refarch.cqrs.trader.app.AmqpConfiguration.defineExchange(AmqpConfiguration.java:25) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:699) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
… 17 common frames omitted
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_201]
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:1.8.0_201]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_201]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_201]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_201]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_201]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_201]
at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_201]
at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.1.2.jar:5.1.2]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:955) ~[amqp-client-5.1.2.jar:5.1.2]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907) ~[amqp-client-5.1.2.jar:5.1.2]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:847) ~[amqp-client-5.1.2.jar:5.1.2]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:449) ~[spring-rabbit-2.0.4.RELEASE.jar:2.0.4.RELEASE]
… 31 common frames omitted

Thanks
Aniwesh