BHL
Archive
This is a read-only archive of the BHL Staff Wiki as it appeared on Sept 21, 2018. This archive is searchable using the search box on the left, but the search may be limited in the results it can provide.

ActiveMQ&Stomp

Common tasks


Manage mutiple activemq instances:

Port information

There are mutiple activemq instances running on server mamdible, providing JMS service to three versions of BHL: integration, test, production.
Each version uses different ports to communicate and admin:

Instance-integration:
Instance-production:
Instance-test:

Location


For different instance, the backup data, log and config files are located under:
/opt/activemq/apache-activemq-5.5.1/instance-<integration/production/test>


Dependencies


Installation

ActiveMQ is installed on the common service host bhl-mandible.

ActiveMQ isn't supported by the debian dist, it need to be installed manually. Now we are using version 5.5.1

Install location:/opt/activemq

Inststallation steps:

Test:
Using the following command to check whether port 61616 is up:
  1. netstat -an|grep 61616

Setup Stomp

<transportConnectors>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613"/>

</transportConnectors>
Test running:
$con = new Stomp("tcp://bhl-mandible.nhm.ac.uk:61613");
$Sent message with body 'test'
$Received message with body 'test'

Setup mutiple instances

Configure store-and-forward ActiveMQ message broker bridge between Fedora

This configuration allows Fedora to use the ActiveMQ which is running on host bhl-mandible to send update message.

Steps:

Test running:

public class TestActiveMQ implements MessagingListener{
 
 private String textPath = "./";
 
 MessagingClient messagingClient;
 public void start() throws MessagingException {
 Properties properties = new Properties();
 properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
 "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
 //properties.setProperty(Context.PROVIDER_URL, "tcp://bhl-int.nhm.ac.uk:61616");
 properties.setProperty(Context.PROVIDER_URL, "tcp://bhl-mandible.nhm.ac.uk:61616");
 properties.setProperty(JMSManager.CONNECTION_FACTORY_NAME, "ConnectionFactory");
 properties.setProperty("topic.fedora", "fedora.apim.*");
 messagingClient = new JmsMessagingClient("example1", this, properties, false);
 messagingClient.start();
 }
 public void stop() throws MessagingException {
 messagingClient.stop(false);
 }
 
 public void onMessage(String clientId, Message message) {
 
 String messageText = "";
 try {
 messageText = ((TextMessage)message).getText();
 } catch(JMSException e) {
 System.err.println("Error retrieving message text " + e.getMessage());
 }
 System.out.println("Message received: " + messageText + " from client " + clientId);
 writeText("receiveMessage", "Message received: " + messageText + " from client " + clientId);
 }
 
 public void writeText(String textname,String date){
 
 File filePath=new File(textPath);
 if(!filePath.exists()){
 filePath.mkdirs();
 }
 try {
 FileWriter fw =new FileWriter(textPath+File.separator+textname);
 fw.write(date);
 
 if(fw!=null)
 fw.close();
 } catch (IOException e) {
 
 e.printStackTrace();
 }
 
 
 }
 
 public static void main(String[] argus){
 TestActiveQ acq = new TestActiveQ();
 try{
 acq.start();
 }
 catch(Exception e){
 }
 
 }
 
}