如何在 Wildfly 中使用 CLI 设置消息传递子系统
Posted
技术标签:
【中文标题】如何在 Wildfly 中使用 CLI 设置消息传递子系统【英文标题】:How to set up messaging subsystem using CLI in Wildfly 【发布时间】:2014-09-15 07:06:12 【问题描述】:有人有使用 CLI 在 Wildfly 中设置消息传递子系统的示例脚本吗?
完美的例子是 CLI 需要让服务器运行standalone.xml,并且在运行 CLI 脚本后,它具有在standalone-full.xml 中定义的消息传递子系统。
到目前为止,我发现的所有示例都假设消息传递子系统已经到位。
【问题讨论】:
有理由不只使用standalone-full.xml吗? 因为standalone-full.xml 包含所有内容。我们正在尝试自动化部署过程,并且希望它能够按照我们的需要运行。 很公平。所以你可以从/extension=org.jboss.as.messaging:add(module=org.jboss.as.messaging)
开始,然后是/subsystem=messaging:add
。这将为您提供具有默认值的基本子系统。
我不确定你想要的所有默认值,它会存在:)
这可以帮助我入门。我也被指向wildscribe.github.io/Wildfly/8.1.0.Final/subsystem/messaging/… 如果我运行最终脚本,我会在这里发布。
【参考方案1】:
这是添加消息的脚本。这会添加消息传递子系统,并使其在运行standalone-full.xml 时看起来像子系统。
/extension=org.jboss.as.messaging:add()
batch
/subsystem=messaging:add
/subsystem=messaging/hornetq-server=default:add
/subsystem=messaging/hornetq-server=default/:write-attribute(name=journal-file-size, value=102400L)
/subsystem=messaging/hornetq-server=default/address-setting=#:add(address-full-policy="PAGE", \
dead-letter-address="jms.queue.DLQ", expiry-address="jms.queue.ExpiryQueue", expiry-delay=-1L, \
last-value-queue=false, max-delivery-attempts=10, max-size-bytes=10485760L, message-counter-history-day-limit=10, \
page-max-cache-size=5, page-size-bytes=2097152L, redelivery-delay=0L, redistribution-delay=-1L, send-to-dla-on-no-route=false)
/subsystem=messaging/hornetq-server=default/in-vm-connector=in-vm:add(server-id=0)
/subsystem=messaging/hornetq-server=default/in-vm-acceptor=in-vm:add(server-id=0)
/subsystem=messaging/hornetq-server=default/http-connector=http-connector:add(socket-binding="http", param=http-upgrade-endpoint="http-acceptor")
/subsystem=messaging/hornetq-server=default/http-connector=http-connector-throughput:add(socket-binding="http", param=http-upgrade-endpoint="http-acceptor-throughput", batch-delay=50)
/subsystem=messaging/hornetq-server=default/http-acceptor=http-acceptor:add(http-listener="default")
/subsystem=messaging/hornetq-server=default/http-acceptor=http-acceptor-throughput:add(http-listener="default", param=batch-delay=50, direct-deliver=false)
/subsystem=messaging/hornetq-server=default/connection-factory=InVmConnectionFactory:add(connector="in-vm"=>undefined, entries = ["java:/ConnectionFactory"])
/subsystem=messaging/hornetq-server=default/connection-factory=RemoteConnectionFactory:add(connector="http-connector"=>undefined, entries = ["java:jboss/exported/jms/RemoteConnectionFactory"])
/subsystem=messaging/hornetq-server=default/pooled-connection-factory=hornetq-ra:add(connector="in-vm"=>undefined, entries=["java:/JmsXA","java:jboss/DefaultJMSConnectionFactory"])
/subsystem=messaging/hornetq-server=default/security-setting=#:add()
/subsystem=messaging/hornetq-server=default/security-setting=#/role=guest:add(consume=true, create-durable-queue=false, create-non-durable-queue=true, delete-durable-queue=false, delete-non-durable-queue=true, manage=false, send=true)
jms-queue add --queue-address=ExpiryQueue --durable=true --entries=["java:/jms/queue/ExpiryQueue"]
jms-queue add --queue-address=DLQ --durable=true --entries=["java:/jms/queue/DLQ"]
run-batch
【讨论】:
【参考方案2】:这是新 Wildfly 10 (ActiveMQ Artemis) 的更新 CLI 命令
>>添加消息子系统
/extension=org.wildfly.extension.messaging-activemq:add()
/subsystem=messaging-activemq:add
/:reload
/subsystem=messaging-activemq/server=default:add
/subsystem=messaging-activemq/server=default/security-setting=#:add
/subsystem=messaging-activemq/server=default/address-setting=#:add(dead-letter-address="jms.queue.DLQ", expiry-address="jms.queue.ExpiryQueue", expiry-delay="-1L", max-delivery-attempts="10", max-size-bytes="10485760", page-size-bytes="2097152", message-counter-history-day-limit="10")
/subsystem=messaging-activemq/server=default/http-connector=http-connector:add(socket-binding="http", endpoint="http-acceptor")
/subsystem=messaging-activemq/server=default/http-connector=http-connector-throughput:add(socket-binding="http", endpoint="http-acceptor-throughput" ,params=batch-delay="50")
/subsystem=messaging-activemq/server=default/in-vm-connector=in-vm:add(server-id="0")
/subsystem=messaging-activemq/server=default/http-acceptor=http-acceptor:add(http-listener="default")
/subsystem=messaging-activemq/server=default/http-acceptor=http-acceptor-throughput:add(http-listener="default", params=batch-delay="50", direct-deliver="false")
/subsystem=messaging-activemq/server=default/in-vm-acceptor=in-vm:add(server-id="0")
/subsystem=messaging-activemq/server=default/jms-queue=ExpiryQueue:add(entries=["java:/jms/queue/ExpiryQueue"])
/subsystem=messaging-activemq/server=default/jms-queue=DLQ:add(entries=["java:/jms/queue/DLQ"])
>>此时需要刷新
/subsystem=messaging-activemq/server=default/connection-factory=InVmConnectionFactory:add(connectors=["in-vm"], entries=["java:/ConnectionFactory"])
/subsystem=messaging-activemq/server=default/connection-factory=RemoteConnectionFactory:add(connectors=["http-connector"], entries = ["java:jboss/exported/jms/RemoteConnectionFactory"])
/subsystem=messaging-activemq/server=default/pooled-connection-factory=activemq-ra:add(transaction="xa", connectors=["in-vm"], entries=["java:/JmsXA java:jboss/DefaultJMSConnectionFactory"])
/subsystem=ee/service=default-bindings/:write-attribute(name="jms-connection-factory", value="java:jboss/DefaultJMSConnectionFactory")
/subsystem=ejb3:write-attribute(name="default-resource-adapter-name", value="$ejb.resource-adapter-name:activemq-ra.rar")
/subsystem=ejb3:write-attribute(name="default-mdb-instance-pool", value="mdb-strict-max-pool")
>>添加消息队列
/subsystem=messaging-activemq/server=default/jms-queue=MyQueue:add(entries=[java:/jms/queue/MyQueue])
所有命令都可以作为批处理命令运行,也可以像这样单独运行:
$SERVER_CLI_PATH --connect --user=$SERVER_USER --password=$SERVER_PASSW --command="line with command"
【讨论】:
【参考方案3】:要在 WildFly 14 中设置消息传递,我必须使用单独的 CLI 脚本文件进行配置,否则 jboss-cli
将失败并出现 JBTHR00004: Operation was cancelled
异常,可能是由于重新加载不完整。如果您仍然遇到这些错误,请将sleep
命令添加到运行 CLI 脚本的 shell 脚本中。
添加消息扩展,1-add-messaging-extension-and-subsystem.cli
:
batch
# Add messaging extension
/extension=org.wildfly.extension.messaging-activemq:add()
# Add messaging subsystem
/subsystem=messaging-activemq:add
run-batch
/:reload
添加消息服务器仅允许虚拟机内连接器,2-add-messaging-server.cli
:
batch
# Add messaging server with default configuration, allow only in-VM connectors
/subsystem=messaging-activemq/server=default:add
/subsystem=messaging-activemq/server=default/security-setting=#:add
/subsystem=messaging-activemq/server=default/address-setting=#:add( \
dead-letter-address="jms.queue.DLQ", \
expiry-address="jms.queue.ExpiryQueue", \
max-size-bytes="10485760", \
message-counter-history-day-limit="10", \
page-size-bytes="2097152")
/subsystem=messaging-activemq/server=default/in-vm-connector=in-vm:add( \
server-id="0",params=buffer-pooling=false)
/subsystem=messaging-activemq/server=default/in-vm-acceptor=in-vm:add( \
server-id="0",params=buffer-pooling=false)
/subsystem=messaging-activemq/server=default/jms-queue=ExpiryQueue:add( \
entries=["java:/jms/queue/ExpiryQueue"])
/subsystem=messaging-activemq/server=default/jms-queue=DLQ:add( \
entries=["java:/jms/queue/DLQ"])
/subsystem=messaging-activemq/server=default/connection-factory=InVmConnectionFactory:add( \
connectors=["in-vm"], \
entries=["java:/ConnectionFactory"])
/subsystem=messaging-activemq/server=default/pooled-connection-factory=activemq-ra:add( \
transaction="xa", \
connectors=["in-vm"], \
entries=["java:/JmsXA java:jboss/DefaultJMSConnectionFactory"])
# Configure default connection factory in the EE subsystem
/subsystem=ee/service=default-bindings/:write-attribute(name="jms-connection-factory", value="java:jboss/DefaultJMSConnectionFactory")
# Configure message-driven beans in the EJB subsystem
/subsystem=ejb3:write-attribute(name="default-resource-adapter-name", value="$ejb.resource-adapter-name:activemq-ra.rar")
/subsystem=ejb3:write-attribute(name="default-mdb-instance-pool", value="mdb-strict-max-pool")
run-batch
/:reload
如果您还需要 HTTP 连接器,请参阅@petr-hunka 的回答。
【讨论】:
以上是关于如何在 Wildfly 中使用 CLI 设置消息传递子系统的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 jboss-cli 在 WildFly 17 中创建 JMS 队列