## Running the Producer

### Using Ant

Use `ant producer` to send a given number of messages to a queue or topic.

### The code explained

The producer Ant target points to the `producerTool.java` class, which again uses `ActiveMQConnectionFactory` to connect to the broker, as shown in Example 4.1.

The producer uses `createQueue()` or `createTopic()` to publish to a destination.

| Note
If the destination already exits, the `createQueue()`and `createTopic()`are simply used to attach to the destination.

Example 4.3. Attaching to a Queue or Topic

    // Create the session
    Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
    if (topic) {
       destination = session.createTopic(subject);
    } else {
       destination = session.createQueue(subject);
    }