> Multicast Messaging Example
> This section demonstrates how to use multicast messaging, as described in Multicast.
> In this example, you will enable multicast in the EMS server and configure a multicast channel, over which the server can broadcast multicast messages. You will also create a multicast-enabled topic named multicastTopic and associate it with the multicast channel, allowing subscribers to receive messages published to multicastTopic over multicast.
> Multicast channels can only be configured statically by modifying the configuration files. There are no commands in the administration tool to configure multicast channels.
> Stop the EMS Server
> Stop the server by using the shutdown command in the administration tool:
> tcp://localhost:7222> shutdown
> You will be asked to restart the server once it has been configured for multicast.
> Enable the EMS Server for Multicast
> To enable multicast in the server, set the multicast property to enabled in the tibemsd.conf configuration file:
> multicast = enabled
> Create a Multicast Channel
> The EMS server broadcasts messages to consumers over multicast channels. Each channel has a defined multicast address and port. Messages published to a multicast-enabled topic are sent by the server and received by the subscribers on these multicast channels.
> To create a multicast channel, add the following definition to the multicast channels configuration file, channels.conf:
> [multicast-1]
> address=234.5.6.7:1
> Start the EMS Server
> Start the EMS server as described in Running the EMS Server.

> | On a computer running a UNIX system, the EMS server (as well as the multicast daemon) must have root privileges. This can be done either by running the EMS server from a root user account, or the EMS server can be setuid (set user ID) root, allowing any user to run tibemsd with the required root privileges. Root privileges are required because multicast uses raw sockets.
> | On a computer running Windows, you can also start the EMS server from the Start menu, following the path Programs > TIBCO > TIBCO EMS 5.1 > Start EMS server.

> In the administration tool, use the show topics command to confirm that multicastTopic is multicast-enabled as indicated by a ‘+’ in the M column:
> tcp://localhost:7222> show topics
> Topic Name SNFGEIBCTM Subs Durs Msgs Size
> multicastTopic ---------+ 0 0 0 0.0 Kb
> Enable a Topic for Multicast
> In order to make a topic multicast-enabled it must be associated with a multicast channel through its channel property.
> To create a multicast-enabled topic, use the administration tool to issue the following command:
> > create topic multicastTopic channel=multicast-1
> Start the Multicast Daemon
> Start the Multicast Daemon as described in Starting the Multicast Daemon.
> Start the Subscriber Client
> Creating a multicast subscriber follows the same steps as creating a non-multicast subscriber, except that a multicast subscriber requires a session acknowledgment mode of com.tibco.tibjms.Tibjms.NO_ACKNOWLEDGE.
> To start user1 as a multicast subscriber:

> 1. | In a command line window, navigate to the EMS_HOME/samples/java folder.

> 2. | Enter setup to set the environment and classpath:

> > setup

> 3. | Execute the tibjmsMsgConsumer client to assign user1 as a subscriber to the multicastTopic topic with a Session acknowledgment mode of NO_ACKNOWLEDGE:

> > java tibjmsMsgConsumer –topic multicastTopic –user user1 –ackmode NO

> 4. | In the administration tool, use the show consumers command to confirm that user1 is a multicast subscriber to multicastTopic as indicated by a + in the M column:

> tcp://optimist:7222> show consumers topic=multicastTopic

> | Id | Conn | User | T | Topic | SASNM | Pend Msgs | Pend Size | Uptime
> | 2 | 4 | user1 | T | multicastTopic | +N--+ | 0 | 0 | 0:03:17

> Start the Publisher Client and Send Messages
> Setting up a client to publish multicast message is no different from setting up a client to send publish and subscribe messages. Because the topic is enabled for multicast in the EMS server, the message producer does not need to follow any additional steps.
> To create the message publisher:

> 1. | In a new command line window, navigate to the EMS_HOME/samples/java folder.

> 2. | Enter setup to set the environment and classpath:

> > setup

> 3. | Execute the tibjmsMsgProducer client to direct user1 to publish some messages to the multicastTopic topic:

> > java tibjmsMsgProducer -topic multicastTopic -user user1 hello multicast
> where ’hello’ and ’multicast’ are separate messages.

> | In this example, user1 is both a publisher and subscriber.

> The messages are displayed in the subscriber’s window.

Copyright © TIBCO Software Inc. All Rights Reserved.