ActiveMQ&Stomp
Common tasks
- start:bhladmin@bhl-mandible:$ sudo /etc/init.d/activemq start
- stop:bhladmin@bhl-mandible:$ sudo /etc/init.d/activemq stop
- restart:bhladmin@bhl-mandible:$ sudo /etc/init.d/activemq restart
Manage mutiple activemq instances:
- /opt/activemq/apache-activemq-5.5.1/instance-<instance name>/bin/:$./instance-<instance name> start/stop/restart
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:
- JMS message and fedora communication port:61616
- Stomp protocol port: 61613
- Admin port: 8161
Instance-production:
- JMS message and fedora communication port:61617
- Stomp protocol port: 61614
- Admin port: 8162
Instance-test:
- JMS message and fedora communication port:61618
- Stomp protocol port: 61615
- Admin port: 8163
Location
- Installation location:/opt/activemq
- Backup data location:/opt/activemq/apache-activemq-5.5.1/data
- Log location:/opt/activemq/apache-activemq-5.5.1/data/activemq.log
- Config files:/opt/activemq/apache-activemq-5.5.1/conf
- activemq.xml: This is the basic config file for activemq.The things can be configured including ports,
transport connectors, network connectors,persistence providers & locations, ect.- log4j.properties: log configured file.
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
- JDK
- Fedora(If it needs to be used as a bridge to send the messages from fedora)
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:
- netstat -an|grep 61616
Setup Stomp
- Open activemq.xml, add a connector to the broker using the stomp URL:
<transportConnectors>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613"/>
</transportConnectors>
Test running:
$con = new Stomp("tcp://bhl-mandible.nhm.ac.uk:61613");
- Run first.php by using command: php first.php, you can see:
$Sent message with body 'test'
$Received message with body 'test'
Setup mutiple instances
- cd /opt/activemq/apache-activemq-5.5.1/
- bin/activemq create instance-<instance name>
- cd instance-<instance name>
- chmod 755 bin/instance-<instance name>
- bin/instance-<instance name> setup ~/.activemqrc-instance-<instance name>
- change the port information in activemq.xml and jetty.xml under /opt/activemq/apache-activemq-5.5.1/instance-<instance name>/conf
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:
- Create the Fedora activemq.xml file, put it in FEDORA_HOME/server/config
<beans xmlns:amq="http://activemq.apache.org/schema/core">
<!-- ActiveMQ JMS Broker configuration -->
<amq:broker id="broker" useShutdownHook="false">
<amq:managementContext>
<amq:managementContext connectorPort="1093" createConnector="false"/>
</amq:managementContext>
<!-- Your remote broker, configured with failover -->
<amq:networkConnectors>
<amq:networkConnector name="fedorabridge" dynamicOnly="true" uri="static:(failover:(tcp://0.0.0.0:61616))"/>
</amq:networkConnectors>
<!-- The directory where Fedora will store the ActiveMQ data -->
<amq:persistenceAdapter>
<amq:amqPersistenceAdapter directory="file:/mnt/nfs/dev/opt/archival-storage/fedora/data/activemq-data/localhost/amq"/>
</amq:persistenceAdapter>
</amq:broker>
<!-- Set this to prevent objects from being serialized when
passed along to your embedded broker; saves some overhead processing -->
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="objectMessageSerializationDefered" value="false"/>
</bean>
</beans>
- Change the java.naming.provider.url parameter in fedora.fcfg
<param name="java.naming.provider.url" value="vm://localhost?brokerConfig=
xbean:file:/mnt/nfs/dev/opt/archival-storage/fedora/server/config/activemq.xml"/>
- Drop the jars xbean-spring-3.4.3.jar and spring-context-2.5.6.jar files into the Fedora webapp WEB-INF/lib directory
- restart Fedora
Test running:
- Run the test case provideing here to establish the connection with bhl-mandible.nhm.ac.uk
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){
}
}
}
- The setup works if it prompts "connectionTo JMS- connected", and each time Fedora has update, this test client can receive the update message.