Wednesday, December 21, 2011

WebSphere Message Broker version 8 is out!

Hot on the heels of the latest goodness in WebSphere MQ, it’s the turn of IBM’s Enterprise Service Bus – WebSphere Message Broker – to get a major new update.
WMB v8.0 was announced back in early October and has just arrived ready for  download in versions for distributed platforms, System z mainframes, and as a Hypervisor Edition for Linux and AIX (to be provisioned via the IBM Workload Deployer appliance).
As I did with WMQ last month, I wanted to take a moment to break out and highlight some of the key things in this release that you may have missed from the announcement letter. This won’t be a comprehensive list of everything, but I  want to point out some of the cooler features that you’ll want to be aware of. So, here we go…
(I’ve included a few screenshots to whet your appetite, click for larger versions!)
A simpler development experience
Version 8 brings a number of enhancements to the development experience, but one worth highlighting is what we call “Apps and Libs” – the idea that sets of message flows may be grouped into a unit called an Application which can be deployed, stopped and started as a whole. With Libraries, there are also truly re-usable assets like .esql files, or sub-flows, which can be deployed and updated separately, and invoked dynamically at runtime. This is a key change in the way that the Broker works – previously, sub-flows were compiled into the main flow and changing one required redeployment of all flows using it… they are now dynamically linked when needed, so they can be deployed and replaced more easily.
A new standards-based parser and message modeler
A new Data Format Description Language (DFDL, which you’ll sometimes hear called “daffodil”) enables any text or binary data to be understood within the message model. The Broker has had the “MRM” for many years, so of course could already do this, but DFDL is a new industry standard which can supersede the MRM (of course, you can continue to use your existing flows and message formats – you’re not forced to use DFDL). There’s a new mapper, too.
More importantly, coming along with DFDL and the mapper is a really, really nice set of utilities for testing message models inside the Toolkit – you’ll now be able to confirm that the model matches the test data without having to go through a full model->deploy-> test-at-runtime cycle. I saw this demo’ed at the WebSphere Technical Conference in Berlin during October and was blown away by it – it would have saved me a lot of time back in my consulting days!
Comprehensive .NET support
If you have .NET applications, assemblies, or services on the Windows platform, and you want to access those from your message flows – you can. If you want to write your message flow logic using C# or VB.NET or any .NET 4.0 CLR-supported language, using Visual Studio – you can.
If you don’t know how to get started with this stuff, the Toolkit has a new .NET Pattern to lead you by the hand and get you going quickly, and project wizards for Visual Studio.So, if you want a high-performance ESB platform that connects “anything to anything”, with minimal need to learn new skills, and run it on Windows with deep .NET integration – this release is going to cover your requirements.
Web administration
Delivered in version 8 is a first stage in making the Broker more easy to administer from a lightweight client – a web browser. Whilst power users and existing administrators can continue to use the Message Broker Explorer GUI, there is now an easy way to enable an optional web interface for basic administration tasks. Continuing the theme of simplicity the product has followed for a while, no additional moving parts (app or web servers) are required! Version 8.0 provides read-only views of running Applications and access to the log – more capabilities will be rolled into this interface in the future.
Record and Replay
Sometimes, when you are dealing with a set of end-to-end flows of data between applications, you may want the capability to record what is going on, and to replay specific scenarios and sets of events. This could be the case in audit, test, and many other scenarios. Another of the massive enhancements in version 8 is the Broker’s response to this requirement – again delivered using the same simple, lightweight interface offered by the web administration tool.
This also builds on technology around monitoring that has been progressively built into the Broker over the past couple of releases, so there are some really solid foundations and it is straightforward to set up.
Richer, yet easier to use
Just as I highlighted in my piece about WebSphere MQ 7.1, the Hursley teams have been strongly focused on “consumability” (translation for non-IBM-speakers = UX) for a number of years now. WMB continues to add capabilities that make it a richer, stronger integration platform, but also smooths out rough edges seen in earlier releases and is just… well… more productive to use. There’s even a drive to reduce the jargon and make the Broker logs more easy to understand, with new Activity Logging which aims to explain what a flow is doing in plain language (“GET message queue X”, “Update DB table Z”, and so on).
Taken together, the new wizards, web interfaces, integrated testing tools, message modelling tools, reduced dependencies, lightweight deployment with apps and libs… the combination just makes it a much more enjoyable experience for developer and administrators. And there’s a new installer, too.
The “papercuts” and node additions lists are huge: new JMSReceive node; new options for the File nodes; new Connect:Direct nodes; WS-ReliableMessaging support in the SOAP nodes; ability to install without root privileges; dynamic configuration of services without the need to restart execution groups… the list just goes on! Check out the product Information Center for more details on all of the features I just don’t have space to list.
… and finally…
Huge congratulations to some hard-working development teams in Hursley, Toronto and Bangalore in getting this release out there. As I’ve said before, I’ve been using the Broker for 10 years now and it just keeps getting better, and better. These guys are a very strong set of developers who turn out a fantastic, high quality product every time. Special thanks to MGK, @mqmatt, and @domstorey for some of the screenshots in this post :-)
Footnote: version 8.0 is friendly to developers who use Ubuntu, too! :-) Anton (my go-to guy on all things Debian – listen to him!) has some good advice about running WMB or WMQ on Ubuntu and Debian

Friday, November 11, 2011

Settings up Message Broker Command environment

Run mqsiprofile script

Running Commands:
Commands must be lower case
Component names case sensitive
Start/Stop/Delete Broker:
Start: mqsistart BrokerName
Stop: mqsistop BrokerName

–q after name stops associated queue manager
–i after name stops immediately
Delete: mqsideletebroker BrokerName [options]
Note: Broker must be stopped before it can be deleted
Start/Stop/Delete Configuration Manager:
Start: mqsistart ConfigMgrName
Stop: mqsistop ConfigMgrName
–q after name stops associated queue manager
Delete: mqsideleteconfigmgr [ConfigMgrName] [options]
–n flag to delete configuration repository
-w flag deletes all files in the configuration manager’s work path
Start/Stop/Delete UserNameServer:
Start: mqsistart UserNameServer
Stop: mqsistop UserNameServer
–q after name stops associated queue manager
Delete: mqsideleteusernameserver [options]
–q after name deletes associated queue manager
–w after name deletes all files in the work path associated with the User Name Server
Specifying Username and password:
You can specify the following flags along with the commands
–i userid
–a password
If you leave, -a flag black; it will prompt you for password.
Changing Broker
mqsichangebroker BrokerName [options]
-s — User Name Server queue manager name
-j — Enable publish/subscribe for the broker
-d — Disable publish/subscribe for the broker
-t — Run the broker as a trusted MQ application
-n — Stop running the broker as a trusted MQ application
-g — Configuration timeout — maximum time for response from an execution group
-k — Configuration delay timeout — maximum time for response from a broker
Changing Configuration Manager
mqsichangeconfigmgr [ConfigMgrName] [options]
-s — User Name Server queue manager name
-j — Maximum Java virtual machine heap size in megabytes. The default is 128.
Changing User name server
mqsichangeusernameserver [options]
-r — Refresh interval being the amount of time before the User Name Server interrogates
the security subsystem for changes to users or groups
-g — The name of the authentication data source
-j — Indicates use of a data source containing users and group information instead of
using the operating system
-o — Indicates use of the operating system users and group information
Note: before executing above change commands, the respective component must be stopped.
Execution Groups:
Create: mqsicreatexecutiongroup [options]
Delete: mqsideleteexecutiongroup [options]
-i host
-p port number of the Configuration Manager-q Config Manager QM
-q queue manager of Configuration Manager
-b Broker name
–e Execution group name
-w timeout
- v tracefile name
Start: mqsistartmsgflow [options]
Stop: mqsistopmsgflow[options]
-i host
-p port number of the Configuration Manager-q Config Manager QM
-q queue manager of Configuration Manager
-b Broker name
–e Execution group name
-m specific flow within the execution group
-w timeout
- v tracefile name
Report message flow statistics: mqsireportflowstats broker_name [options]
-e ExecutionGroupName
-f MessageFlow
-a Specify that the command modifies archive accounting and statistics collection.
-s Specify that the command modifies snapshot accounting and statistics collection.
-g Specifies that the command applies to all execution groups that belong to the broker.
-j Specifies that the command applies to all message flows that belong to the execution group.
Change message flow statistics: mqsichangeflowstats [options]
-e ExecutionGroupName
-f MessageFlow
-a Specify that the command modifies archive accounting and statistics collection.
-s Specify that the command modifies snapshot accounting and statistics collection.
-g Specifies that the command applies to all execution groups that belong to the broker.
-j Specifies that the command applies to all message flows that belong to the execution group.
-o OutputFormat; usertrace/xml
mqsideploy [options]
-p port number of the Configuration Manager
-q queue manager of Configuration Manager
-b Broker
-e Execution Group
-a BAR file
-w Timeout
Listing resources
mqsilist [options]
- a List all the components
- brokerName The name of the broker for which you want to list resources
- e egName selects an execution group within a broker
Security Commands
Create ACL: mqsicreateaclentry ConfigmgrName [options]
List ACL entries: mqsilistaclentries [options]
Delete ACL entries: mqsideleteaclentries [options]
-g GroupName The local group to which this entry refers
-u UserName The user name to which this entry refers
-m MachineName The name of the machine from which a specified user can connect.
-a The specified user name can be on any machine.
-x AccessLevel
F: Full control
D: Deploy
E: Edit
V: View
-b Broker
-e ExeGroup, You must specify the b flag if you specify this flag.
-s Subscription The object is a subscription object, and its name is specified as a parameter.
-r The object refers to the root topic.
-t The object refers to the main topology.
-p The object refers to the “allresources” resource type
Backup/Restore Commands
Backup: mqsibackupconfigmgr ConfigMgrName –d DirPath [options]
Restore: mqsirestoreconfigmgr ConfigMgrName –d DirPath –a ArchiveName [options]
-w WorkPath Specifies the path for the Configuration Manager repository
Problem Determination
Report Trace: mqsireporttrace [options]
Change Trace: mqsichangetrace [options]
-componentName The name of a broker, a Configuration Manager, or the fixed name User Name Server;
-e egName The label of the execution group for which a report is required. This option is valid only if you have specified a broker as the component.
-f messageFlow The label of the message flow for which a report is required. This option is valid only if you have specified a broker as the component, and an execution group.
-u Derive report information from the user trace.
-t Derive report information from the service trace.
-b Request a report for agent function.
-n Report the setting of the Trace node switch.
Read Trace: mqsireadlog BrkName [options] –o Output_file
-e Egroup
-o Outputfilename
-f Read the log file directly from the file system
-u Read the log contents from the user trace log.
-t Read the log contents from the service trace log.
Format Trace: mqsiformatlog –i input_file -o Output_file
Publish/subscribe commands
Add, remove, and list MQ publish/subscribe broker network
Add: mqsijoinmqpubsub Broker_name [options]
-p ParentQueueManagerName, The name of the queue manager that hosts the WebSphere MQ Publish/Subscribe broker to which this WebSphere Message Broker broker is to be joined
Remove: mqsiclearmqpubsub Broker_name [options]
-n NeighborQueueManagerName, The name of the queue manager that hosts the WebSphere MQ Publish/Subscribe broker for which the association as a neighbor is being removed.
List: mqsilistmqpubsub Broker_name
Database commands
(windows) mqsicreatedb DBName [options]
-i ServiceUserID, The user ID under which the DatabaseInstanceMgr service runs
-a ServicePassword, The password for the ServiceUserID
-p PortNumber, The TCP/IP port number that this component will use on the local machine
-e DbType
-u DbUserID, An additional user name that requires access to the database that is created by this command.
(unix/Linux) mqsi_setupdatabase [options]
-Database_Home_Directory, The name of the directory in which the database is (or will be) installed
Change user ID andpassword information
mqsisetdbparms BrokerName [options]
-n ResourceName or AdapterName
-u UserId or EISUserId
-p Password
-d This parameter deletes the user ID and password pair for this resource from the registry.
-a Specify this parameter to process the mqsisetdbparms command when the broker itself is running.

How to Schedule a Java Application from Windows Task Scheduler

If you want a Java application to run daily, hourly or on some other frequency and the server is Windows, this entry provides a step-by-step method for configuring such a system.  Below are the basic steps in brief:

1. write java class or obtain classes to use
2. move class or classes to root location:  java_home\bin (where java.exe is found)
3. put your classes in the file path descending from bin, as usual (i.e. com.utilities.mycompany)
4. put .properties file (if any) in bin directory (java_home\bin )
5. create a batch file on desktop or anywhere.  Inside batch file place your java class invocation
6. point to batch file in Windows Scheduler.
7. Configure Windows Scheduler to run on some schedule.

Details of Process (uses same sequence as above):
1. write java class or obtain classes to use. Can also use jar files, of course.
2. move class or classes to root location:  java_home\bin (where java.exe is found). If you don't have java_home environment variable set search for java.exe and use the JRE/JDK folder that matches the version of Java JVM you're using. It's often found in c:\program files\java...
3. put your classes in the file path descending from bin, as usual (i.e. com.utilities.mycompany).  See image below: 

4. put .properties file (if any) in bin directory (java_home\bin ). In this example: C:\Program Files\Java\jdk1.5.0_09\bin
5. create a batch file on desktop or anywhere.  Inside batch file place your java class invocation.  Here is a sample batch file. Of course, you can get as fancy and include as many features as you want. Check the Internet for details about how to write batch (.bat) files...this is an entire subject in itself:
echo Running Java Move File utility
echo %date% %time% Start of Running Java Move File utility> c:\test.log
cd C:\Program Files\Java\jdk1.5.0_09\bin
java -cp ".;" com.util.cmmc.CopyAndDelete 1>>c:\test.log 2>>&1
echo Batch file completed
Intrepretation of bat file (in parentheses)
echo Running Java Move File utility (just a comment)
echo %date% %time% Start of Running Java Move File utility> c:\test.log  (this line puts a timestamp and title into a file called test.log)
cd C:\Program Files\Java\jdk1.5.0_09\bin (this ensures you are in correct directory to launch java JVM)
java -cp ".;" com.util.cmmc.CopyAndDelete 1>>c:\test.log 2>>&1 (this is the key line that launches your app. In this case it's called CopyAndDelete. Classpath has no supporting classes besides default classes. Note that standard output statements are written to the same log file)
echo Batch file completed (just a comment)
6. point to batch file in Windows Scheduler. Open Windows Scheduler by Contol Panel | Scheduled Tasks (Windows 2003 Server Enterprise Ed.). Create a new task. Point to the .bat file you just created:

7. Configure Windows Scheduler to run on a schedule. Use Advanced settings if you need to further define scheduled run time.

Advanced settings allow repeating schedule and frequency not found in the basic settings:

Setup is now complete. You can do a sample run (independent of schedule) by right clicking on the Scheduled Task (at Explorer level - folder level) and clicking Run.
Note that there are many options for creating a .bat file, setting up scheduler, logging, etc. This blog entry shows how to do a basic, workable system from start-to-finish.  You can use this as a starting point and construct what you need from this example working system

Sunday, May 22, 2011

Work Life Balance

One of the common problems today every one of us goes through in our day to day life is work life balance. I have heard this term recently multiple times and I wanted to blog about my opinion on the same.

Work life and personal life are the two sides of the same coin. Traditionally creating and managing a balance between the work-life was considered to be a woman’s issue. But increasing work pressures, globalization and technological advancement have made it an issue with both the sexes, all professionals working across all levels and all industries throughout the world. Achieving "work-life balance" is not as simple as it sounds.

Work life and personal life are inter-connected and interdependent. Spending more time in office, dealing with clients and the pressures of job can interfere and affect the personal life, sometimes making it impossible to even complete the household chores. On the other hand, personal life can also be demanding if you have a kid or aging parents, financial problems or even problems in the life of a dear relative. It can lead to absenteeism from work, creating stress and lack of concentration at work.

Okay, Okay, We have heard this n number of times… so what do you want to say?

In my opinion following are the list of items which can help in achieving WLB.

Understand what you want: You are the best judge of what you want. If you want an aggressive career then there will be obviously more work to do. If you are a person who talks about aggressive career only during the time of appraisal then convince yourself about that. If you are not able to decide what you want, no one can help you in this. IMHO, you can’t have the best of both worlds.

Prioritize your tasks: Yes, prioritize your work. In the morning, when you get into office, list the items which are important that needs to be completed before you leave for the day.

Have 2 sets of list. One is Critical and the other one is Non-Critical Items. Critical are the list of items which you need to deliver or which your boss has asked you to deliver.

Non-critical are the items which you need to complete, but it is not high priority. May be you can delegate to your team members (if possible).

There are cases where you need to move the items between the groups. You need to prioritize this based on the situation.

Make a habit to complete the items in the list. If you have a very long to do list, then it means that you are not following what you have agreed to do. Mark items as completed as you move along and clear the list on a regular basis.

Time Management: Everyone talks about the need for managing time, but it’s the hardest thing to implement. Maintain a list where you could specify the time spent during my day. Capture this for a week or so and analyse. You do not have to share it with your boss. It’s for you. Apart from work, there could be items like Tea break, Cigarette break, Lunch break, Browsing, Chatting, Personal E-mails, Socializing chats, Evening Walk and Reading News Feeds etc. Find out where majority of your time goes.

Once you know where your time is spent, cut those items and see how it can be used effectively at work. As far as I know, we do not work more than 6 focused hours (most of the cases its only less than 4 focused hours of work). If we can effectively spend these hours in the day time then you can definitely complete your work by 6 PM and there is no need to stay after 6.

If you have client calls in the evening/support the client side team, then work out a plan with your manager so that you can start little late. You can use this time in the morning to do your personal work. Adjust your work hours. I have seen the benefits of adjusting the work hours. It really helps.

Exercise/Stay fit: The other thing which we normally miss is exercise. It could be because of laziness or not wanting to do any physical activity. Exercise will keep you fit and make you feel better.

Hobby: Have a hobby/life outside your work. If things are not going well, this will help you focus in things outside work.

In summary, work Life Balance starts with understanding what you want. It requires a person to know how to prioritize work, say NO whenever required and manage his/her time better. It’s all about how you can juggle the elephants.

More work and less personal life create problems. The same way, more of personal life and less work also will not help. It’s not possible to exactly get the balance. IMHO, it’s more about adaptability and how one can adjust to the situation.


Saturday, May 21, 2011

Learn To Put A Full-Stop !!!

You can remain stable when you learn to apply a full-stop.

In any difficult situation, check if you are having thoughts like, "why do things happen with me like this or why is this person behaving in this way" etc. you can never remain stable when you have such questions. Tell yourself that it is much easier to put a full-stop(.) than putting a question mark(?). understand the difference between worrying and finding solutions and worrying. If there is a solution, find it, if there isn't let things take care of themselves and put a full-stop.

Overcome & Control Your Weakness !!

The way to overcome your weakness is to feel that the weakness is not yours.

Check what weakness within you is not enabling you to attain success in the way you want to. Also check how many times during the day you have felt caught up with that weakness. See yourself in your perfect form and let there be the thought in your mind that the weakness is not yours and you are the one who has developed it in yourself. This thought helps you to gain mastery over that weakness and gives you the control to overcome it.

Friday, January 7, 2011

Publish/Subscribe Messaging Can Be Simple with WebSphere MQ

Combine publish/subscribe messaging, JMS, and WebSphere MQ to build powerful message-oriented applications simply.

essage-oriented middleware (MOM) decouples applications by allowing them to communicate using one of two messaging models: point-to-point messaging and publish/subscribe messaging. The models differ in fundamental ways, but neither requires applications to know the other’s implementation details. Point-to-point messaging achieves only partial decoupling of applications, because you still need to know where to put messages. Publish/subscribe provides a higher degree of independence and reduces design complexity in many cases, but it requires more coding and configuration. Traditionally, MOM shops have opted for point-to-point messaging to avoid the more complex requirements of publish/subscribe.
Enter IBM WebSphere MQ (WMQ), Version 7. This latest release of WMQ aims to make coding and configuring publish/subscribe easier and more intuitive. A previous DevX article focused on the point-to-point messaging capabilities of WMQ. This article explains WMQ's publish/subscribe messaging.

Publish/Subscribe Messaging Overview

Publish/subscribe is the messaging-oriented equivalent of the object-oriented observer design pattern. In publish/subscribe messaging, a sender application creates a message containing the information it wants to send and assigns it a topic that denotes the subject of the information. This message is called a publication. WMQ receives the publication, recognizes the topic, and then distributes the publication to interested applications. Specifically, WMQ publish/subscribe components include:
  • Publisher (information producer): This component generates messages (publications) under a certain subject (topic) and sends the publications to a WMQ queue manager. A publisher knows nothing about the recipient(s) of the information.
  • Figure 1. A Basic Publish/Subscribe Setup: Publish/subscribe includes publishers, subscribers, and a queue manager.
  • Subscriber (information consumer/receiver): This component registers interest in a certain topic(s) with a WMQ queue manager. It also specifies its subscription queue name; that is, the queue where it wants to receive the messages related to this topic. The subscriber knows nothing about the information publishers(s).
  • A publications router: This component passes messages from publishers to topic subscribers. Earlier WMQ versions required a broker component on top of a queue manager to enable publish/subscribe. The broker maintained topics and subscriptions, and it routed publications. In WMQ Version 7, IBM changed this approach significantly. The queue manager is now responsible for topics, subscriptions, and routing publications. Also, MQ Explorer for Version 7 allows you to create topics and subscriptions graphically.
Figure 1 shows a basic MQ publish/subscribe setup.
A publish/subscribe system can have many publishers and many subscribers, and often, two or more queue managers communicating with one another. Also, an application can be both a publisher and a subscriber.

A Publish/Subscribe Scenario

Suppose a company sends notifications to its clients via email and Short Message Service (SMS) based on information received from various information providers (say, news and weather services). If the company adds another provider (say, for entertainment), it will have to configure the new provider to write messages to both SMS and email queues. Figure 2 shows the point-to-point implementation for this use case, and Figure 3 shows the publish/subscribe implementation.

Figure 2. Point-To-Point Implementation for This Use Case: Point-to-point messaging requires sender applications to know the queue names for all receiving applications.

Figure 3. Publish/Subscribe Implementation for This Use Case: The email and SMS applications subscribe to the topics generated by providers and automatically receive the information.
As you can see, publish/subscribe is less complex, and adding a new provider requires less effort. When the email and SMS applications subscribe to the topics generated by providers, they automatically receive the information. The providers know nothing about the email and SMS queues.

Set Up Your Own Publish/Subscribe Use Case

In this section, you will create a publish/subscribe setup resembling part of the use case in Figure 3. You will create a publisher for the news topic and two subscriptions for the email and SMS applications using the following procedure:
  1. Create a queue manager.
  2. Create a news topic.
  3. Create subscription queues.
  4. Create subscriptions.
  5. Create Java Messaging Services (JMS)-administered objects.
  6. Write publisher and subscriber classes.
  7. Run the classes.
This tutorial uses MQ Version 7 on Windows XP. (Download a trial version from the IBM web site.) Installation on Windows is straightforward. Just keep all the default values as you go through the installation wizard, but be sure to perform the installation as a user from the administrators group.
Don't worry if you haven't used WMQ before. You will use the Eclipse-based WebSphere MQ Explorer, an easy GUI for administering WMQ, to perform basic definitions.
Start WebSphere MQ Explorer as follows: Start –> All Programs –> IBM WebSphere MQ –> WebSphere MQ Explorer. If this is the first time you are starting MQ Explorer, a welcome screen will appear. Just close the welcome screen.

Create a Queue Manager

  1. In MQ Explorer's Navigator view, right-click Queue Managers and then select New –> Queue Manager. This starts the "Create Queue Manager" wizard.
  2. On Step 1, enter TestQM as the queue manager name and then click Next (see Figure 4).
  3. Click Next on the wizard screens for Steps 2 and 3. At Step 4, make sure "Create listener configured for TCP/IP" is checked and the entered port number is free (see Figure 5), and then click Finish.

Figure 4. Create Queue Manager Wizard, Step 1: Enter the queue manager name.

Figure 5. Create Queue Manager Wizard, Step 4: Check the port number for the queue manager's listener.

Create a News Topic

  1. Under TestQM, right-click Topics and then select New –> Topic to start the "New Topic" wizard.
  2. Type News.Topic as the topic name (see Figure 6). This represents the WMQ administrative object used to manage the topic. Click Next.
  3. On the topic properties page, type News in the "Topic string" field (see Figure 7). This string is used when creating JMS administered objects to refer to the News topic. Click Finish.

Figure 6. Create Topic, Step 1: Enter the topic's administrative object name.

Figure 7. Create Topic, Step 2: Enter the topic's string name.

Create Subscription Queues

Next, you will set up news publications to be delivered to Subscription queues. Create two queues for the email and SMS applications:
  1. Under TestQM, right-click Queues then select New –> Local Queue to start the "New Local Queue" wizard.
  2. In the name field, type Email.Queue and click Finish.
  3. Repeat the above steps to create another queue called SMS.Queue.

Create Subscriptions

In order to receive a topic's publications, subscribers have to register interest in the topic. They use subscriptions to accomplish this. You can can create subscriptions programmatically or through MQ Explorer. Through the following steps, you will create two subscriptions using MQ Explorer:
  1. Under TestQM, right-click Subscriptions and then select New –> Subscription to start the "New Subscription" wizard.
  2. In the name field, type EmailSubscription and click Next (see Figure 8).
  3. In the "Change properties" page, press the Select button next to the "Topic name" and then select News.Topic from the displayed topics list. Press OK. On the same page, type Email.Queue in the destination name field (see Figure 9). Click Finish.

  4. Figure 8. Create Subscription, Step 1: Enter the subscription name.

    Figure 9. Create Subscription, Step 2: Select topic and enter subscription queue.
  5. Repeat the above steps to create another subscription called SMSSubscription with the topic set to News.Topic and the destination name set to SMS.Queue.

A Quick Test for Your Publish/Subscribe Setup

Perform the following to verify you have correctly completed the setup for the News topic:
  1. Under TestQM, click Topics.
  2. In the right pane, right click News.Topic and select "Test Publication" to open the test window.
  3. In the message data field, type "publish/subscribe test" (or any other text), click the "Publish message" button, and then click the Close button. This should distribute the message to the subscriber queues Email.Queue and SMS.Queue.
  4. Under TestQM, click Queues.
  5. In the right pane, right click Email.Queue and select "Browse Messages." When the browse messages window opens, search the "Message Data" column for the text you entered. You should also see the same message in SMS.Queue.
  6. Right click Email.Queue and select "Clear Messages." Click the Clear button in the "Clear queue" window. Do the same for SMS.Queue.

Create JMS-Administered Objects

JMS applications require you to wrap vendor-specific objects in JMS-administered objects. To store JMS-administered objects, create a file-based Java Naming and Directory Interface (JNDI) namespace. Start by adding a new initial context:
  1. Right-click JMS-Administered Objects and then select Add Initial Context.
  2. On Screen 1:
    • Select "File System" for "Where is the JNDI located."
    • For the Bindings directory, browse to C:\JNDI-Directory (This directory has to exist).
    • Keep note of the factory class and provider URL; you will use them in the Java code (see Figure 10).
    • Figure 10. Add Initial Context Wizard: You will use the factory class and provider URL in the sample class.
    • Click Finish.
Next, create a JMS Connection factory and destinations under the Initial Context.

Create a Connection Factory

  1. Right-click Connection Factories and then select New –> Connection Factory. On the first screen, type TestQMConnectionFactory in the name field and click Next (see Figure 11). You will use TestQMConnectionFactory in the JNDI lookup.
  2. Click Next on Step 2, Step 3, and Step 4.
  3. On the last page, select the connection tab (on the left) and then click the Select button to select TestQM as "Base queue manager" (See Figure 12). Click Finish.

Figure 11. Create Connection Factory, Step1: Type a factory name.

Figure 12. Create Connection Factory, Final Step: Select TestQM as the base queue manager.

Create Destinations

JMS destinations wrap WMQ topics and queues. Create a destination corresponding to the News topic:
  1. Right-click destinations and select New –> Destination to start the "New Destination" wizard.
  2. In the first step, enter NewsTopic in the Name field and change the Type field to Topic (See Figure 13). Click Next.
  3. Click Next on the second screen.
  4. On the last page (Change properties), type News in the Topic field and then click Finish (See Figure 14). This is the topic string you defined when you created the News topic.

Figure 13. Create Topic Destination, First Step: Make sure you change the Type field to Topic.

Figure 14. Create Topic Destination, Final Step: Make sure you type News (not News.Topic).
Create two destinations corresponding to the subscriber queues:
  1. Right-click destinations and then select New –> Destination to start the new "Destination wizard."
  2. In the first step, type EmailQueue in the Name field and then click Next.
  3. Click Next on the second screen.
  4. On the last page, click the Select button next to the "Queue Manager" field and select TestQM from the list.
  5. Click the Select button next to the Queue field and select Email (See Figure 15). Queue from the list. Click Finish.
  6. Repeat the above steps to create another Destination called SMSQueue for SMS.Queue. Your destinations should look like the ones in Figure 16.

Figure 15. Create Queue Destination, Last Step: Select queue manager and queue.

Figure 16. A Third Destination Called SMSQueue for SMS.Queue: You have created three destinations.

Coding JMS Publishers and Subscribers

After you have defined your topics and subscriptions through the MQ Explorer, writing publisher and subscriber applications is easy. To publish a message, you must write a message to a topic (just as you would with a queue). Subscribers simply read messages from queues. The downloadable source code for this article uses generic JMS interfaces, which treat queues and topics uniformly as destinations. It provides compiled classes that include a News publisher and two subscribers (corresponding to the Email and SMS applications).
The following are brief explanations of the classes.

JNDIUtil Class

This class includes methods to retrieve objects by name through JNDI lookup (see Listing 1). You will use methods in this class to retrieve references to the JMS objects you have already defined.

NewsPublisher Class

This class publishes messages to the News topic (see Listing 2). The starting point is a connection factory lookup. You use the factory to create a connection:
factory= jndiUtil.getConnectionFactory("TestQMConnectionFactory"); 
connection = factory.createConnection();
You use the connection object to create a session:
session = connection.createSession( transacted, Session.AUTO_ACKNOWLEDGE);
To publish messages, retrieve a News destination object, create a MessageProducer, and then send messages:
destination = jndiUtil.getDestination("NewsTopic");
producer = session.createProducer(destination);
TextMessage message = session.createTextMessage("No News is Good News!");

EmailSubscriber and SMSSubscriber

These two classes represent the email application and the SMS application (see Listing 3 and Listing 4). Because you already defined subscriptions in MQ Explorer, the two applications simply read messages from the subscriber queues. The code is similar to the NewsPublisher class, except that it uses a MessageConsumer to retrieve messages from queues:
consumer = session.createConsumer(destination);
TextMessage iMsg = (TextMessage) consumer.receive(1000);

Compiling and Running the Sample Classes

The JAR files required to compile and run the sample classes are automatically added to the CLASSPATH environment variable when you install WMQ. The required JARs are located in C:\Program Files\IBM\WebSphere MQ\Java\lib, including the JARs you need for JMS and JNDI. You just need to add the sample classes from the code download to your CLASSPATH environment variable. To publish messages, run the NewsPublisher:
java devx.articles.pubsub.NewsPublisher
Run both subscribers after your run the NewsPublisher to retrieve messages. Each class should retrieve its own copy of the messages published by NewsPublisher:
java devx.articles.pubsub.EmailSubscriber
java devx.articles.pubsub.SMSSubscriber
You're done. Your sample classes should compile and run successfully.
So the next time you're designing messaging-based applications, don't be so quick to dismiss publish/subscribe. Remember this article and how quickly you were able to get started with publish/subscribe messaging.