我正在嘗試使用 Spring Boot 和 Docker 部署 ActiveMQ Artemis。Artemis 加上 Spring Boot 作業正常。我正在使用spring-boot-maven-plugin
生成一個胖罐子。當我嘗試將該胖 jar 部署到 Docker 時,我看到接受器已啟動:
AMQ221020:在 localhost:61616 為協議 [CORE] 啟動 EPOLL 接受器
但是我無法從 Docker 外部連接到它。
執行緒“main”中的例外 ActiveMQConnectionTimedOutException[errorType=CONNECTION_TIMEDOUT message=AMQ119013:等待接收集群拓撲超時。組:空]
我正在使用此命令將其運行到 Docker 中:
docker run -p 61616:61616 8bd9ff19ea08
任何的想法?
這里pom.xml
:
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
</parent>
<groupId>SpringBootArtemis2</groupId>
<artifactId>SpringBootArtemis2</artifactId>
<name>Spring Boot Artemis Starter</name>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.source>1.8</java.source>
<spring.boot.version>2.5.6</spring.boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-artemis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Spring啟動組態檔:
@Configuration
@EnableJms
public class SpringBootExampleConfiguration {
@Bean
public ArtemisConfigurationCustomizer customizer() {
return new ArtemisConfigurationCustomizer() {
@Override
public void customize(org.apache.activemq.artemis.core.config.Configuration configuration) {
try {
configuration.addAcceptorConfiguration("netty", "tcp://localhost:61616");
}
catch (Exception e) {
throw new RuntimeException("Failed to add netty transport acceptor to artemis instance", e);
}
}
};
}
}
SpringBootApplication 檔案:
@SpringBootApplication
public class SpringBootExampleMain {
public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootExampleMain.class, args);
}
}
泊塢窗檔案:
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/SpringBootArtemis2-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
EXPOSE 61616
消費者代碼:
ServerLocator locator = ActiveMQClient.createServerLocator("tcp://localhost:61616");
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession();
ClientProducer producer = session.createProducer("example");
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString("Hello");
session.createQueue("example", "example", true);
ClientConsumer consumer = session.createConsumer("example");
producer.send(message);
session.start();
ClientMessage msgReceived = consumer.receive();
System.out.println("message = " msgReceived.getBodyBuffer().readString());
session.close();
I have a different setup exposing OpenWire as well and I have the same behaviour: working fine without docker but not working with docker
uj5u.com熱心網友回復:
連接失敗,因為 netty 接受器正在偵聽本地主機,因此它只能接受來自運行在同一主機/容器上的行程的連接。
要解決此問題,SpringBootExampleConfiguration 應將 netty 接受器設定為偵聽 0.0.0.0,即
configuration.addAcceptorConfiguration("netty", "tcp://0.0.0.0:61616");
Docker 使部署微服務應用程式變得非常容易,但它對生產環境有一些限制。我會看看開源 ArtemisCloud.io 專案,它是一個容器鏡像的集合,提供了一種在 Kubernetes 上部署 Apache ActiveMQ Artemis Broker 的方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/360716.html