I have an application which uses ActiveMQ broker. In order to have some integration test I have created another tool which puts messages into the queue.
What I want to achieve is to avoid using physical ActiveMQ but initialize AMQ together with starting my application, then connect my tool which loads messages into this queue and at the end close all connections. I can do sth like this using the same process (unit tests) when I start AMQ transport like vm://localhost but it doesn't work when I want to connect from another process to put sht onto the queue. Has anybody faced similar issue?
The vm transport cannot communicate outside the JVM in which it was started.
Combining peer transport with vm allows for embedded brokers to discover remote brokers over discovery networks (multicast, jgroups, etc), but this seems like overkill, suggest using tcp for simplicity.
//create embedded broker using tcp
BrokerService broker = new BrokerService();
broker.addConnector("tcp://localhost:61616");
broker.start();
//remote client use tcp to connect, but local JVM client can use vm
vm:broker:(tcp://localhost:61616)
Related
I want to start a BrokerService on a remote machine in the network instead.
Instead of having
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:61616)"));
I want to have:
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://remoteMachine:61616)"));
So essentially I have an application that should do everything remotely. It should start an ActiveMQ BrokerService remotely from my code and then use that broker to send and receive messages. Once the application has done its job it should shut the BrokerService down.
I have tried the code above but it keeps on giving me a JVM binding exception:
Failed to bind to server socket: tcp://remoteMachine:61616 due to: java.net.BindException: Cannot assign requested address: JVM_Bind
I can see that port is not in use but still throws this exception.
I think you've misunderstood what BrokerFactory.createBroker() actually does. It can't create a broker on a remote machine. It can only create a local broker. The URI which you pass to it simply provides the configuration for the local broker. The syntax for this URI is documented here.
Since you're passing the name of a remote machine when attempting to create a local broker the broker creation process fails because it can't bind a listener to that name. The name must be the name of the machine where you're executing the createBroker() method or, more generally, localhost.
ActiveMQ doesn't provide any way to start a broker on a remote server. However, this kind of functionality really isn't in the domain of a message broker. That's the kind of functionality that would be provided by the operating system itself. For example, in Linux you'd have a script that would SSH into a remote machine and execute a command (e.g. starting a message broker).
Is there any way to get notification from server whenever it is on?
my requirement is when ever ActiveMQ is on a piece of code will run automatically
in ActiveMQ is there is no load on startup
Create a publisher in your language of choice that periodically sends a test message to ActiveMQ.
Create a subscriber in your language of choice that receives the test messages and notifies you via your mechanism of choice that it has successfully received a test message.
The Apache ActiveMQ broker supports discovery with IP multicast.
Applications can use discovery for JMS clients to auto-detect a Message Broker to connect to.
This could also be used to monitor a broker's status, using Java MultiCast support.
To invoke a piece of code when the broker is started, you can perhaps base it off either an embedded Camel route or broker interceptor. The idea being that when the broker is started, so will these components and thus allows them to issue whatever sort of notification you require.
Recently I started using ActiveMQ to act as a Message Middleware in my new project, this is the first time I try use ActiveMQ, the projects I had participated before used our previous company's inner message framework like Swallow. So before I begin implementing the system, I need to clear some design points.
Cases in our system will use ActiveMQ include sending mail, sending tasks to queue and doing tasks from queue, asynchronous request/response, so what kind of protocol and network connection is the right choice for our cases? I list some protocols and network connection options here:
ActiveMQ protocols:
MQTT
WS
Openwire
Stomp
Stomp
ActiveMQ Network connections:
VM
TCP
UDP
HTTP
Failover
Discovery
I will also consider the aspects of HA and cluster for my system, so can anybody gives me some ideas to decide how to choose the protocol and network connection?
Thanks a lot.
Openwire has historically been the default protocol the NIO transport can give performance improvements over TCP so if you use ActiveMQ as your only broker use one of these. However using AMQP means in the future you could possibly use RabbitMQ, another popular Message Broker. There are others, STOMP or MQTT are lightweight, VM is designed to be used when the application resides on the same machine as the broker so gets very high throughput.
As ActiveMQ can enable all protocols by default do some quick tests to gain an idea of throughput on the specific application you are building. Then consider the above points in making a decison.
Regarding UDP, TCP, HTTP I would choose TCP. UDP is unreliable and TCP is more than adequate in sending 1000's per second. HTTP could be useful if your company has awkward firewall rules.
I would wrap this in a failover transport. I have never used discovery but would argue this is more advanced and not required initially as it requires a discovery agent. Its only purpose is too discover the ActiveMQ broker dynamically (although you still have to know where the discover agent is).
So i wrote a program to connect to a Clustered WebLogic server behind a VIP with 4 servers and 4 queues that are all connected( i think they call them distributed...) When i run the program from my local machine and just get JMS Connections, look for messages and disconnect, it works great. and by that i mean it:
iteration #1
connects to server 1.
look for a message
disconnects
iteration #2
connects to server 2.
look for a message
disconnects
and so on.
When i run it on the server though, the application picks a server and stick to it. It will never pick a new server, so the queues on the other servers don't ever get worked. like with a "sticky session" setup... My OS is Win7, and the Server os is Win2008r2 JDK is identical for both machines.. How is this configured client side? The server implementation uses "Apache Procrun" to run it as a service. but i haven't seen too many issues with that part...
is there a session cookie getting written out somewhere?
any ideas?
Thanks!
Try disabling 'Server Affinity' on the JMS Connection factory. If you are using the Default Connection Factory, define your own an disable Server Affinity.
EDIT:
Server Affinity is a Server-side setting, but it controls how messages are routed to consumers after a WebLogic JMS Server receives the message. The other option is to use round-robin DNS and send to only one hostname that resolves to a different IP(Managed Server) such that each connection goes to a different server.
I'm pretty sure this is the setting you're looking for :)
I am considering an architecture where I have clients that are intermittently connected to a network. I would like to store messages created on these clients in a JMS queue when the network is not available and have these forwarded to a central message broker when the clients are on the network. (The user has control over the network, e.g. dialing in, so it's not an intermittent connection like with a mobile phone.)
Are there any JMS implementations that provide this feature?
You can embed an activeMQ broker into your application
http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html
Then, I suppose (did not test) that you could use ActiveMQ features which allow you to dispatch messages accross a net of brokers, using the discovery of brokers feature,
http://activemq.apache.org/clustering.html
or simply by adding a queue consumer server side, then dispatching through other brokers through this consumer.
Hope it helps.
The Glassfish Open Message Queue can be embedded (or run stand-alone) in version 4.4 (Support the ability for a broker to run "in process" with any client.). It is very light-weight, and will support other client languages over the STOMP protocol in version 4.4 - besides Java and C. - https://mq.dev.java.net/4.4.html