concept producer in category activemq

This is an excerpt from Manning's book ActiveMQ in Action.
Once the JMS producer is connected, it then sends 2,000 messages and shuts down. This is the number of messages the consumer is waiting to consume before it shuts down. So as the messages are being sent by the producer in terminal three, flip back to terminal two and watch the JMS consumer as it consumes those messages. Here’s the output you’ll see in terminal two:
[java] [Thread-2] Received: 'Message: 0 sent at: Thu Oct 14 21:23:56 MDT 2010 ...' (length 1000) [java] [Thread-2] Received: 'Message: 1 sent at: Thu Oct 14 21:23:56 MDT 2010 ...' (length 1000) [java] [Thread-2] Received: 'Message: 2 sent at: Thu Oct 14 21:23:56 MDT 2010 ...' (length 1000) ... [java] [Thread-2] Received: 'Message: 1999 sent at: Thu Oct 14 21:23:56 MDT 2010 ...' (length 1000)Again, the output has been truncated for brevity but this doesn’t change the fact that the consumer received 2,000 messages and shut itself down. At this time, both the consumer and the producer should be shut down, but the ActiveMQ broker is still running in the first terminal. Take a look at the first terminal again and you’ll see that ActiveMQ appears to not have budged at all. This is because the default logging configuration doesn’t output anything beyond what’s absolutely necessary. If you’d like to tweak the logging configuration to output more information as messages are sent and received, you can do so. Logging will be covered further in chapter 14.
We’ve already covered the performance gains that can be achieved if you use nonpersistent delivery for messages. In ActiveMQ nonpersistent delivery is reliable, in that delivery of messages will survive network outages and system crashes (as long as the producer is active—it holds messages for redelivery in its failover transport cache). But you can also get the same performance gain for persistent messages by setting the useAsyncSend property on the message producer’s connection factory, as shown next.
Listing 13.16. Creating the producer
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://fast"); cf.setCopyMessageOnSend(false); Connection connection = cf.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic("test.topic"); final MessageProducer producer = session.createProducer(topic); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); for (int i =0; i < 1000000;i++) { TextMessage message = session.createTextMessage("Test:"+i); producer.send(message); }