Using failover URI in ActiveMQ Ajax client -
i using ajax client connect activemq. can activemq ajax client support failover transport? use embedded jetty inside broker uses vm transport forward messages broker.
the ajax client sends messages broker using url
http://localhost:8161/api/amq how can bring failover support this.
fwiw using amq.js.
thanks, bhanu
add following getting , setter functions end of object returned in amq.js file (i.e. after testpollhandler function):
seturi: function(newuri) { uri = newuri; }, geturi: function() { return uri; } then switch next server if connection not established:
var activemq_servers = ["http://server1:8161/ajax/amq","http://server2:8161/ajax/amq"]; var amq = org.activemq.amq; function connectstatushandler(connected) { if (!connected) { var index = _.indexof(activemq_servers, amq.geturi()); var newindex = (index + 1) % activemq_servers.length; var uri = activemq_servers[newindex]; amq.seturi(uri); if (window.console) { console.log("lost connection. attempting next server: " + uri); } } } amq.init({ uri: activemq_servers[0], logging: true, timeout: 20, connectstatushandler: connectstatushandler, logging: true }); you'll need cors enabled in jetty server hosts ajaxservlet if establish connections across servers. that, enable built in jetty cors filter following configuration in web.xml file:
<filter> <filter-name>cross-origin</filter-name> <filter-class>org.eclipse.jetty.servlets.crossoriginfilter</filter-class> <init-param> <param-name>allowedorigins</param-name> <param-value>*</param-value> </init-param> <init-param> <param-name>allowedmethods</param-name> <param-value>*</param-value> </init-param> <init-param> <param-name>allowedheaders</param-name> <param-value>*</param-value> </init-param> </filter> <filter-mapping> <filter-name>cross-origin</filter-name> <url-pattern>/amq/*</url-pattern> </filter-mapping>
Comments
Post a Comment