...
- Contact its-iam-help@lists.hawaii.edu to request access to the UH Message Broker:
- Messages are published into an exchange. You need to provide a name for the exchange where your messages will be published. The name must end with -exchange or -pii-exchange (if sensitive information is published). e.g.
- student-status-exchange
- You can have one or more exchanges under a 'vhost'. If you plan to have many exchanges that fall under the umbrella of a more generic concept, you can provide that as your vhost, e.g.
- banner (as the vhost which contains the exchanges below)
- student-status-exchange
- student-pii-exchange
- faculty-status-exchange
- faculty-pii-exchange
- banner (as the vhost which contains the exchanges below)
- Provide a desired username for the UH Message Broker account that will have full access to your exchange. This should be something related to your application, not your personal username, and it is often the same as the vhostname of the specific process that is doing the message publishing, e.g.
- banner-messaging-producer
- Provide the IP addresses of the systems that will connect to the UH Message Broker
- Of course, you should define the format of the messages you'll be publishing into your exchanges , and make it available to applications interested in consuming your messages.
- It is probably in your best interest to exercise tight control over the queues that applications will declare in order to consume messages from your exchange(s). This ensures that the applications are using the correct settings, will not lose messages if not properly defined, etc. We suggest the following:
- Applications should not freely create queues. You We should declare the accounts, queue and bindings (more on this later) for each application. You can request by emailing its-iam-help@lists.hawaii.edu the following info:
- Provide us with the name of your vhost
- Provide us with the name of your exchange
- Provide a username for the application, e.g.
- portal
- By default, we will create a queue by appending .prod (or .test) to the username, e.g.
- portal.prod
- If you took the default of setting up a topic exchange, provide us with the bindings for that application's queue. These are the patterns for the message routing keys corresponding to the messages that the application is interested in, e.g.
- # (application is interested in all your messages)
- registration.# (application only wants registration messages)
- #.MAN.# (application wants all messages but only for UH Manoa)
- Applications should not freely create queues. You We should declare the accounts, queue and bindings (more on this later) for each application. You can request by emailing its-iam-help@lists.hawaii.edu the following info:
- Since there will be no real consumers when you start developing, we will provide you with a default test queue that your publisher can consume its own messages from. Otherwise nothing will happen. Your queue will typically be the username your provided followed by .test, e.g.
- student-status-exchange will have a queue called banner.test
- Messages are published into an exchange. You need to provide a name for the exchange where your messages will be published. The name must end with -exchange or -pii-exchange (if sensitive information is published). e.g.
- Download the RabbitMQ Java client from http://www.rabbitmq.com/download.html (there should be libraries and examples for other languages there)
- Here is a SamplePublisher.java you can try.
- Replace the following with your own values:
- yourVhostNameHere
- yourExchangeNameHere
- yourRabbitMqUsernameHere
- yourRabbitMqPasswordHere
- esb-test.its.hawaii.edu with esb.hawaii.edu when your code is ready to use the production RabbitMQ service.
No Format import java.io.*; import java.security.*; import com.rabbitmq.client.*; public class SamplePublisher { private final static String exchangeName = "yourExchangeNameHere"; private final static String vhostName = "yourVhostNameHere"; private final static String username = "yourRabbitMqUsernameHere"; private final static String password = "yourRabbitMqPasswordHere"; private final static boolean durable = true; private final static boolean exclusive = true; private final static boolean autoDelete = false; private final static boolean autoAck = true; public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("esb-test.its.hawaii.edu"); factory.setPort(5671); factory.setVirtualHost(vhostName); factory.setUsername(username); factory.setPassword(password); factory.useSslProtocol(); // Tells the library to setup the default Key and Trust managers for you // which do not do any form of remote server trust verification Connection conn = factory.newConnection(); Channel channel = conn.createChannel(); String message = "<registration> <action>add</action> <courseID>MAN_MATH_101</courseID> <studentID>12345678</studentID> </registration>"; String routingKey = "registration.add.MAN"; channel.basicPublish(exchangeName, routingKey, null, message.getBytes()); System.out.println(" [x] Sent '" + message + "'"); channel.close(); conn.close(); } }
- Replace the following with your own values:
- To quickly compile and run the above, you could save the above code as SamplePublisher.java in the same directory where you downloaded the above Java client (we tried it with rabbitmq-java-client-bin-2.7.1):
- javac -cp rabbitmq-client.jar SamplePublisher.java
- java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar SamplePublisher
- That's it!
...
- See Producer Code Example.
- Typically, you should set the delivery_mode property to 2 (persistent messages) as shown in the example.
- See Producer Code Example.