The Java EE 6 Tutorial

ProcedureTo Deploy and Run the Clients for the Synchronous Receive Example Using NetBeans IDE

  1. Deploy and run the Producer example:

    1. Right-click the producer project and select Properties.

    2. Select Run from the Categories tree.

    3. In the Arguments field, type the following:


      queue 3
      
    4. Click OK.

    5. Right-click the project and select Run.

      The output of the program looks like this (along with some application client container output):


      Destination type is queue
      Sending message: This is message 1 from producer
      Sending message: This is message 2 from producer
      Sending message: This is message 3 from producer

      The messages are now in the queue, waiting to be received.


      Note –

      When you run an application client, there is usually a noticeable delay between the first two application client container messages and the remainder of the output.


  2. Now deploy and run the SynchConsumer example:

    1. Right-click the synchconsumer project and select Properties.

    2. Select Run from the Categories tree.

    3. In the Arguments field, type the following:


      queue
      
    4. Click OK.

    5. Right-click the project and select Run.

      The output of the program looks like this (along with some application client container output):


      Destination type is queue
      Reading message: This is message 1 from producer
      Reading message: This is message 2 from producer
      Reading message: This is message 3 from producer
  3. Now try running the programs in the opposite order. Right-click the synchconsumer project and select Run.

    The Output pane displays the destination type and then appears to hang, waiting for messages.

  4. Right-click the producer project and select Run.

    The Output pane shows the output of both programs, in two different tabs.

  5. Now run the Producer example using a topic instead of a queue.

    1. Right-click the producer project and select Properties.

    2. Select Run from the Categories tree.

    3. In the Arguments field, type the following:


      topic 3
      
    4. Click OK.

    5. Right-click the project and select Run.

      The output looks like this (along with some application client container output):


      Destination type is topic
      Sending message: This is message 1 from producer
      Sending message: This is message 2 from producer
      Sending message: This is message 3 from producer
  6. Now run the SynchConsumer example using the topic.

    1. Right-click the synchconsumer project and select Properties.

    2. Select Run from the Categories tree.

    3. In the Arguments field, type the following:


      topic
      
    4. Click OK.

    5. Right-click the project and select Run.

      The result, however, is different. Because you are using a topic, messages that were sent before you started the consumer cannot be received. (See Publish/Subscribe Messaging Domain, for details.) Instead of receiving the messages, the program appears to hang.

  7. Run the Producer example again. Right-click the producer project and select Run.

    Now the SynchConsumer example receives the messages:


    Destination type is topic
    Reading message: This is message 1 from producer
    Reading message: This is message 2 from producer
    Reading message: This is message 3 from producer