after fumbling around internet, it's surprise can't find sample configuration pushing remote message queue using jms in wildfly 10 activemq (artemis). worsen situation standalone-full.xml
not bound schema (why???) , when found xsd here on github, contains no documentation stating each node/attribute means , values can put in what.
below original configuration standalone-full.xml.
<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0"> <server name="default"> <security-setting name="#"> <role name="guest" delete-non-durable-queue="true" create-non-durable-queue="true" consume="true" send="true"/> </security-setting> <address-setting name="#" message-counter-history-day-limit="10" page-size-bytes="2097152" max-size-bytes="10485760" expiry-address="jms.queue.expiryqueue" dead-letter-address="jms.queue.dlq"/> <http-connector name="http-connector" endpoint="http-acceptor" socket-binding="http"/> <http-connector name="http-connector-throughput" endpoint="http-acceptor-throughput" socket-binding="http"> <param name="batch-delay" value="50"/> </http-connector> <in-vm-connector name="in-vm" server-id="0"/> <http-acceptor name="http-acceptor" http-listener="default"/> <http-acceptor name="http-acceptor-throughput" http-listener="default"> <param name="batch-delay" value="50"/> <param name="direct-deliver" value="false"/> </http-acceptor> <in-vm-acceptor name="in-vm" server-id="0"/> <jms-queue name="expiryqueue" entries="java:/jms/queue/expiryqueue"/> <jms-queue name="dlq" entries="java:/jms/queue/dlq"/> <connection-factory name="invmconnectionfactory" entries="java:/connectionfactory" connectors="in-vm"/> <connection-factory name="remoteconnectionfactory" entries="java:jboss/exported/jms/remoteconnectionfactory" connectors="http-connector"/> <pooled-connection-factory name="activemq-ra" transaction="xa" entries="java:/jmsxa java:jboss/defaultjmsconnectionfactory" connectors="in-vm"/> </server> </subsystem>
below cdi queue client able post messages local artemis instance in wildfly.
@applicationscoped public class queueclient { private static final gson gson = new gson(); @resource(mappedname = "java:jboss/defaultjmsconnectionfactory") private connectionfactory connectionfactory; public void sendmessage(string destinationname, object message) throws jmsexception { try (connection conn = connectionfactory.createconnection(); session session = conn.createsession(false, session.auto_acknowledge)) { queue queue = session.createqueue(destinationname); final message consignment = session.createmessage(); consignment.setstringproperty("media_type", "application/json"); consignment.setstringproperty("body", gson.tojson(message)); session.createproducer(queue).send(consignment); } } }
my goal: post messages remote activemq instance.
what have: server url
, topic name
, username
, password
.
my question: how modify configuration achieve goal?
alternative question: if above can't answered, how else achieve goal?
thanks!
have checked following documentation.
it addresses current concern.
thanks.
edit: upon negative flagging of post.
as documentation listed above describes. need create pooled connection factory, uses remote connector , remote connector references ip x socket of remote active mq server. please see documentation on how this, these first 3 steps.
the configuration of such pooled-connection-factory done in 3 steps, , quote:
create outbound-socket-binding pointing remote messaging server: /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-artemis:add(host=, port=61616)
create remote-connector referencing outbound-socket-binding created @ step (1). /subsystem=messaging-activemq/server=default/remote-connector=remote-artemis:add(socket-binding=remote-artemis)
create pooled-connection-factory referencing remote-connector created @ step (2). /subsystem=messaging-activemq/server=default/pooled-connection-factory=remote-artemis:add(connectors=[remote-artemis], entries=[java:/jms/remotecf])
finally, once have pooled connection factory configured, can use jndi resource available jee container. inject pooled connction factory bean , use create session.
here, have example on how send jms message server. in case, matter of fixing connection factory jndi reference pooled connection factory associated remote active mq.
and quote:
@stateless public class jmsservice { @resource(mappedname = "java:jboss/jms/queue/examplequeue") private queue queueexample; @resource(mappedname = "java:/jmsxa") private connectionfactory cf; private connection connection; private messageproducer publisher; private session session; @transactionattribute(transactionattributetype.required) public void sendmessage(string txt) { try { connection = cf.createconnection(); session = connection.createsession(false, session.auto_acknowledge); publisher = session.createproducer(queueexample); connection.start(); textmessage message = session.createtextmessage(txt); publisher.send(message); } catch (exception exc) { exc.printstacktrace(); } { if (publisher != null) try { publisher.close(); } catch (exception ignore) { } if (session != null) try { session.close(); } catch (exception ignore) { } if (connection != null) try { connection.close(); } catch (exception ignore) { } } } }
in case connection factory should:
@inject
@jmsconnectionfactory("java:/jms/remotecf")
private jmscontext context;
one more thing need aware queue inject bean remote queue. way access remote queue doing jndi lookup on the remote active mq server. explained here. http://activemq.apache.org/artemis/docs/1.1.0/using-jms.html#jndi-configuration
and quote interesting part of documentation starts. if follow through, can see how jndi initial context can used lookup artemis queues.
and if client wanted bind queue "queues/orderqueue" jndi properties configured so:
java.naming.factory.initial=org.apache.activemq.artemis.jndi.activemqinitialcontextfactory java.naming.provider.url=tcp://myhost:5445 queue.queues/orderqueue=orderqueue
it possible look-up jms destinations haven't been configured explicitly in jndi context environment. possible using dynamicqueues/ or dynamictopics/ in look-up string. example, if client wanted look-up aforementioned "orderqueue" using string "dynamicqueues/orderqueue". note, text follows dynamicqueues/ or dynamictopics/ must correspond name of destination on server.
please read through artemis configuration on this.
finally, there approach can try explore. , these jms queue bridges. have google up. essentially, jms bridge can allow contents of queue tunneled remote queue. mechanism of bridging should give possibility of programming code if against local artemis jms server, queues being bridged data being read or being published coming or going remote server.
but have inform see works best you.
i sincerly hope helps.
Comments
Post a Comment