This section describes an example of publishing and subscribing, using the administration tool and the client samples.
In general, to run a client sample, you enter appropriate commands in the sample console window and the EMS administration tool. For more information on the sample clients, see the Readme in the sample folder. For further information on the administration tool, see Starting the Administration Tool and Command Listing.
In this chapter, you will use the client samples. You will create a topic and then create two users for that topic. You will give one user permission to subscribe on that topic, and the other user permission to publish on that topic. Then you will publish two messages, and observe as they are received.
This example is simple and limited. For example, in a real application, the users would be connections to working applications, while in this example, users only send and receive messages. This example also does not attempt to include examples of all permissions, properties or commands, and it does not describe any of the queue commands. Nevertheless, the example can give a partial overview of the process.
In this section, you will create a topic. Several topics are included with the client samples. For this sample, however, you will create a new topic. You create topics in the EMS administration tool.
![]() |
You must start the server and the administration tool before creating a topic. For information on running the server, refer to Running the Server. For information on starting the administration tool, refer to Starting the Administration Tool.
|
To begin using the administration tool, see Starting the Administration Tool.
![]() |
On a computer running Windows, you can also start the administration tool from the Start menu, following the path Programs>TIBCO Enterprise Message Service 4.3>Start EMS administration tool.
|
When you have started the administration tool, you need to connect it to the EMS server.
To connect the EMS administration tool to the EMS server, execute one of the following commands:
The screen will display: connected to tcp://localhost:7222
.
It will then display the following prompt: tcp://localhost:7222>
connect [<server URL>] [<user-name>] [<password>]
For more information on this command, see connect.
Once you have connected the administration tool to the server, you can create a new topic.
To create a new topic:
For more information on the create topic
command, refer to create topic. For more information on the commit
command, see commit and autocommit.
You will add the secure
property to the topic. With the secure property added, only users who have been assigned a certain permission can perform the actions allowed by that permission. For example, only users with publish permission on the topic can publish, while other users cannot publish.
If the secure
property is not added to a topic, all authenticated users have all permissions (publish, subscribe, create durable subscribers) on that topic.
For more information on the secure
property, see the section about secure. For more information on topic permissions, see Chapter 9, Authentication and Permissions.
To enable server authorization and add the secure
property to a topic, do the following steps:
set server authorization=enabledThe
authorization
property enables checking of permissions set on destinations.
secure
property to a topic named foo
:addprop topic foo secureFor more information on the
addprop topic
command, refer toaddprop topic
.
Using the client samples, you will create several users and give them various permissions to publish and subscribe to the topic foo
.
The first step is creating the users.
This section illustrates creating users with the administration tool.
To create two users:
You have now created two users.
For more information on the create user
command, refer to create user.
In order to see how permissions affect the ability to publish and receive messages, you will give the two users various permissions on the topic foo
. You will give publish permission to one user, subscribe permission to the second user, and both publish and subscribe to the third user.
To grant permissions to users on the topic foo
:
For more information on the grant topic
command, refer to grant topic.
Next, you will use the client samples to publish and receive on topic foo.
In previous sections, you have created the topic foo
, assigned the property secure
to that topic. You also made two users, and assigned permissions to publish and subscribe on foo
to these users. In this section, you will use the client samples to publish and subscribe on foo.
To publish and subscribe on foo, you will use the client samples.
In order to run the client samples, you must give them commands from within the sample directory. The sample directory contains the compiled samples.
For more information on the samples, refer to the readme
within the sample directory. For more information on compiling the samples, refer to Compiling the Sample Files.
First, you will attempt to start both of your users as subscribers on foo. Because only one user has permission to subscribe on foo, only one of the users will actually start as a subscriber.
You will start the subscribers first, because the subscribers enable you to observe the messages being received when you start the publisher.
To start a subscriber:
setup
Entering setup
sets the environment and classpath, and returns you to the prompt.
java tibjmsTopicSubscriber -topic foo -user user1However, in this example,
foo
is asecure
topic, anduser1
has permission to publish, but not to subscribe. Therefore, you will receive an exception message including the statement:
Operation not permitted
.The window will then return to the prompt.
java tibjmsTopicSubscriber -topic foo -user user2The screen will display a message showing that
user2
is subscribed tofoo.
In this example,
foo
is asecure
topic, anduser2
has permission to subscribe tofoo
.The window does not return to the prompt, because the subscription is running, and no further action needs to be taken.
Setting up the publisher is very similar to setting up the subscriber. However, while the subscriber requires the name of the topic and the user, the publisher also requires messages.
To start the publisher:
The command line window containing the publisher will display a message stating that both messages have been published. The command line windows containing the subscriber will show the two messages being received.
After the messages are published, this window returns to the prompt for further message publishing.
![]() |
Note that if you attempt to use the form: without adding the messages, you will see an error message, reminding you that you must have at least one message text. |
TIBCO Enterprise Message Service™ User’s Guide Software Release 4.3, February 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |