jboss jms 配置
在standalone.xml中
<extensions>
...
<extension module="org.jboss.as.messaging"/>
...
</extensions>
...
<subsystem xmlns="urn:jboss:domain:messaging:1.1">
<hornetq-server>
<persistence-enabled>true</persistence-enabled>
<journal-file-size>102400</journal-file-size>
<journal-min-files>2</journal-min-files>
<cluster-user>admin</cluster-user>
<cluster-password>0</cluster-password>
<failover-on-shutdown>true</failover-on-shutdown><!-- 失败转移 -->
<shared-store>true</shared-store><!--所有服务实例之间共享消息 -->
<connectors>
<netty-connector name="netty" socket-binding="messaging"/>
<netty-connector name="netty-throughput" socket-binding="messaging-throughput">
<param key="batch-delay" value="50"/>
</netty-connector>
<in-vm-connector name="in-vm" server-id="0"/>
</connectors>
<acceptors>
<netty-acceptor name="netty" socket-binding="messaging"/>
<netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
<param key="batch-delay" value="50"/>
<param key="direct-deliver" value="false"/>
</netty-acceptor>
<in-vm-acceptor name="in-vm" server-id="0"/>
</acceptors>
<security-settings>
<security-setting match="#">
<permission type="send" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
</security-setting>
</security-settings>
<address-settings>
<address-setting match="#">
<dead-letter-address>jms.queue.DLQ</dead-letter-address>
<expiry-address>jms.queue.ExpiryQueue</expiry-address>
<redelivery-delay>0</redelivery-delay>
<max-size-bytes>10485760</max-size-bytes>
<address-full-policy>BLOCK</address-full-policy>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
</address-setting>
</address-settings>
<jms-connection-factories>
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
</entries>
</connection-factory>
<connection-factory name="RemoteConnectionFactory">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="RemoteConnectionFactory"/>
<entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
</entries>
</connection-factory>
<pooled-connection-factory name="hornetq-ra">
<transaction mode="xa"/>
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
<jms-destinations>
<!-- http://blog.csdn.net/stefshawn/article/details/6714321。-->
<jms-queue name="Queue">
<entry name="queue/piaoyi"/>
<entry name="java:jboss/exported/jms/queue/piaoyi"/>
</jms-queue>
<jms-topic name="Topic">
<entry name="topic/piaoyi"/>
<entry name="java:jboss/exported/jms/topic/piaoyi"/>
</jms-topic>
</jms-destinations>
</hornetq-server>
</subsystem>
...
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
...
<socket-binding name="messaging" port="5445"/>
<socket-binding name="messaging-throughput" port="5455"/>
...
</socket-binding-group>
修改配置文件standalone-full-ha.xml
......
<interfaces>
<interface name="management">
<inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:192.168.0.102}"/>
</interface>
<interface name="unsecure">
<inet-address value="${jboss.bind.address.unsecure:127.0.0.1}"/>
</interface>
</interfaces>
........
修改<interfaces>下的<interface name="public">,默认是回环地址,把它绑定到自己的外部IP。
使用standalone模式启动jboss,配置文件选用standalone-full-ha.xml
例如,运行 standalone.bat -server-config=standalone-full-ha.xml -Djboss.socket.binding.port-offset=20 -Djboss.node.name=node1
-server-config=?是配置选用什么配置文件启动服务器,这个配置文件必须在JBOSS_HOME\configuration\下存在。
-Djboss.socket.binding.port-offset=? 和 -Djboss.node.name=?其实是实验室环境下使用的,就是为了能在同一台机器上运行多个jboss实例,生产环境中基本没用
其中-Djboss.socket.binding.port-offset=?设置绑定端口的偏移量,意思是在同一台机器上运行多个实例的使用需要绑定不同的端口。
启动后的端口号=配置文件中的端口号 +offset;
-Djboss.node.name=? 是绑定节点的名字,在默认情况下就是主机名。注意在同一个网络内这个节点名称必须不同。
standalone.bat -server-config=standalone-full-ha.xml -Djboss.socket.binding.port-offset=0 -Djboss.node.name=node1
standalone.bat -server-config=standalone-full-ha.xml -Djboss.socket.binding.port-offset=40 -Djboss.node.name=node2
注意客户端连接代码中 通过connection创建session的时候
一定要加上一个用户名密码,这个用户名密码是通过add-user.bat创建的ApplicationRealm
如: ConnectionFactory cf = (ConnectionFactory)context.lookup("jms/RemoteConnectionFactory");
Connection connection = cf.createConnection("test01","12345");