【问题标题】:Spring boot + axon framework starter + distributed command bus using JGroupsSpring boot + axon framework starter + 使用 JGroups 的分布式命令总线
【发布时间】:2018-07-18 18:09:30
【问题描述】:

我目前的目标是使用 Spring Boot 启动器构建一个项目,以使用 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

就像同时定义了两个类。我感到迷茫,有什么线索吗?

问候

弗朗西斯科

【问题讨论】:

  • 这很奇怪弗朗西斯科,不记得在使用 JGroups 分布式设置时发生在我身上的事情。你介意分享你正在使用的所有依赖项吗?这可能会对情况有所了解。
  • 我更新了帖子
  • 我回答了这个问题,虽然我仍然不肯定会解决它...此外,您可以将 Axon Framework 版本升级到 3.3.2。

标签: axon


【解决方案1】:

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


更新

游戏有点晚了,但我注意到您正在使用 spring-boot-devtools 依赖项。请注意,目前 Axon 框架不能很好地与 devtools 配合使用,例如在 this 问题中标记的那样。 您是否尝试过移除依赖来解决手头的问题?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 2014-04-07
    相关资源
    最近更新 更多