Spring Boot + Axon Framework Starter +使用JGroups的分布式命令总线

时间:2018-07-18 18:09:31

标签: axon

我当前的目标是使用Spring Boot Starters构建一个项目,以使用Jgroups测试分布式命令。

运行时收到此消息:收到未知消息:org.axonframework.jgroups.commandhandling.JoinMessage

它来自org.axonframework.jgroups.commandhandling.JGroupsConnector

@Override
public void receive(Message msg) {
    Object message = msg.getObject();
    if (message instanceof JoinMessage) {
        processJoinMessage(msg, (JoinMessage) message);
    } else if (message instanceof JGroupsDispatchMessage) {
        processDispatchMessage(msg, (JGroupsDispatchMessage) message);
    } else if (message instanceof JGroupsReplyMessage) {
        processReplyMessage((JGroupsReplyMessage) message);
    } else {
        logger.warn("Received unknown message: " + message.getClass().getName());
    }
}

当前POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>spring-axon-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-axon-example</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.axonframework</groupId>
        <artifactId>axon-spring-boot-starter</artifactId>
        <version>3.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mariadb.jdbc</groupId>
        <artifactId>mariadb-java-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.axonframework</groupId>
        <artifactId>axon-spring-boot-starter-jgroups</artifactId>
        <version>3.2.1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
</project>

控制台输出

2018-07-20 08:38:01.652  WARN 9439 --- [localhost-29107] o.a.j.commandhandling.JGroupsConnector   : Received unknown message: org.axonframework.jgroups.commandhandling.JGroupsDispatchMessage

应用

package com.example.demo;

import org.axonframework.eventsourcing.eventstore.EventStorageEngine;
import org.axonframework.eventsourcing.eventstore.inmemory.InMemoryEventStorageEngine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class SpringAxonExampleApplication {

public static void main(String[] args) {
    SpringApplication.run(SpringAxonExampleApplication.class, args);
}

@Bean
public EventStorageEngine eventStoreEngine() {
    return new InMemoryEventStorageEngine();
}
}

Applications.properties

spring.datasource.url=jdbc:mariadb://localhost/axoncqrs
spring.datasource.username=1
spring.datasource.password=1
server.port=8033
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.properties.hibernate.globally_quoted_identifiers=true

java.net.preferIPv4Stack=true
axon.distributed.enabled=true
axon.distributed.jgroups.bind-addr=GLOBAL
axon.distributed.jgroups.bind-port=7800
axon.distributed.jgroups.cluster-name=Axon
axon.distributed.jgroups.configuration-file=default_tcp_gossip.xml
axon.distributed.jgroups.gossip.hosts=localhost[12001]
axon.distributed.jgroups.gossip.auto-start=true

这就像是同时存在两个类定义。我感到迷茫,有任何线索吗?

问候

Francisco

1 个答案:

答案 0 :(得分:0)

我希望从您的pom.xml和属性中我可以有所作为。 但是,我唯一能猜到的是,您的类路径/中的Maven存储库中可能有两个不同版本的Axon Framework。 您是否尝试过删除/清除您依赖的所有现有库并再次运行该应用程序?