在 DynamicPropertySource 中设置 TestContainer 的映射端口
Setting mapped port of TestContainer in DynamicPropertySource
给定:TestContainer 作为集成框架,Spring 启动应用程序,ibm mq 作为代理我尝试测试它,无法使用默认设置连接,捕获:
Caused by: com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2538' ('MQRC_HOST_NOT_AVAILABLE').
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:203)
... 118 common frames omitted
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2538;AMQ9204: Connection to host 'localhost(1414)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2538;AMQ9204: Connection to host 'localhost/127.0.0.1:1414' rejected. [1=java.net.ConnectException[Connection refused (Connection refused)],3=localhost/127.0.0.1:1414,4=TCP,5=Socket.connect]],3=localhost(1414),4=,5=RemoteTCPConnection.bindAndConnectSocket]
容器声明:
@Container
static GenericContainer<?> mqContainer = new GenericContainer<>(DockerImageName.parse("ibmcom/mq"))
.withEnv("LICENSE", "accept")
.withEnv("MQ_QMGR_NAME", "QM1")
.withEnv("MQ_USER_NAME","admin")
.withCommand("--volume q1data:/mnt/mqm")
.withExposedPorts(1414);```
yml 文件中队列的所有设置看起来都不相关,因为没有任何端口特定的东西:
ibm:
mq:
channel: DEV.APP.SVRCONN
queue-manager: QM1
user: admin
password: passw0rd
use-i-b-m-cipher-mappings: false
user-authentication-m-q-c-s-p: false
#ssl-cipher-spec: ECDHE_RSA_AES_128_CBC_SHA256
ssl.enabled: false
我问过 TC 框架支持者,他们建议在动态属性中为 spring 设置主机和端口,这似乎是合法的。唯一的问题是我找不到要使用的正确设置。有什么建议吗?
来自此处的教程:https://developer.ibm.com/tutorials/mq-jms-application-development-with-spring-boot/,这些可能是以下 属性:
ibm.mq.connName=localhost(1414)
所以你的 @DynamicPropertySource
可能是这样的:
@DynamicPropertySource
static void registerMqProperties(DynamicPropertyRegistry registry) {
registry.add("ibm.mq.connName",
() -> String.format("%s(%d)",
mqContainer.getHost(),
mqContainer.getFirstMappedPort()));
}
给定:TestContainer 作为集成框架,Spring 启动应用程序,ibm mq 作为代理我尝试测试它,无法使用默认设置连接,捕获:
Caused by: com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2538' ('MQRC_HOST_NOT_AVAILABLE').
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:203)
... 118 common frames omitted
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2538;AMQ9204: Connection to host 'localhost(1414)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2538;AMQ9204: Connection to host 'localhost/127.0.0.1:1414' rejected. [1=java.net.ConnectException[Connection refused (Connection refused)],3=localhost/127.0.0.1:1414,4=TCP,5=Socket.connect]],3=localhost(1414),4=,5=RemoteTCPConnection.bindAndConnectSocket]
容器声明:
@Container
static GenericContainer<?> mqContainer = new GenericContainer<>(DockerImageName.parse("ibmcom/mq"))
.withEnv("LICENSE", "accept")
.withEnv("MQ_QMGR_NAME", "QM1")
.withEnv("MQ_USER_NAME","admin")
.withCommand("--volume q1data:/mnt/mqm")
.withExposedPorts(1414);```
yml 文件中队列的所有设置看起来都不相关,因为没有任何端口特定的东西:
ibm:
mq:
channel: DEV.APP.SVRCONN
queue-manager: QM1
user: admin
password: passw0rd
use-i-b-m-cipher-mappings: false
user-authentication-m-q-c-s-p: false
#ssl-cipher-spec: ECDHE_RSA_AES_128_CBC_SHA256
ssl.enabled: false
我问过 TC 框架支持者,他们建议在动态属性中为 spring 设置主机和端口,这似乎是合法的。唯一的问题是我找不到要使用的正确设置。有什么建议吗?
来自此处的教程:https://developer.ibm.com/tutorials/mq-jms-application-development-with-spring-boot/,这些可能是以下 属性:
ibm.mq.connName=localhost(1414)
所以你的 @DynamicPropertySource
可能是这样的:
@DynamicPropertySource
static void registerMqProperties(DynamicPropertyRegistry registry) {
registry.add("ibm.mq.connName",
() -> String.format("%s(%d)",
mqContainer.getHost(),
mqContainer.getFirstMappedPort()));
}