LibraryToggle FramesPrintFeedback

Change the user name value from "Chatter1" to "Fred" as shown:

<target name="chat1">
  <java classname="Chat" ... >
    ...
    <arg value="-u"/>
    <arg value="Fred"/>
  </java>
</target>

Save the file, and then enter ant chat1 in one of the sample windows, type Hello, and then press Enter. The response line is:

[java] Fred: Hello
[Note]Note

The password parameter requires implementation of security. For these samples, that would require all the user names and their respective passwords be defined in the security store. For information about securing JMS applications see Security Guide.

At this point in exploring JMS, the broker used by the samples is always on the computer where the sample applications run. While you might use a local or an embedded broker, JMS messaging is designed so that the sample applications can run on a computer that has the appropriate libraries, yet can connect to a broker on a different system to produce and consume messages. The standalone broker system would typically be in a location where it can be monitored and provided resources that ensure optimal availability to any applications that use it.

The sample applications provide a -b parameter to specify the protocol, host, and port of the preferred broker. As the default broker configuration specifies the TCP protocol on localhost, listening on port 61616, you can use another installation of the Java, Fuse Message Broker, Ant, and the Exploring JMS files (as described in the previous chapter) on another computer to experience distributed connection. On one host set up and start the broker. On the other host (the remote host), do the same.

Stop the broker on the remote host, then modify the build.xml file on the remote host to add the connection parameter and specify the host name where the broker is running. For example:

<target name="chat1">
  <java classname="Chat" ... >
    ...
    <arg value="-u"/>
    <arg value="Fred"/>
    <arg value="-b"/>
    <arg value="tcp://remoteHostName:61616"/>
  </java>
</target>

Save the build file and then run chat1 in a sample window on each of the computers. When you enter messages in either Chatter_1 window, the subscribers both get the message from the same broker.

Comments powered by Disqus