# JMS task

A JMS task sends a message to a message broker, or takes messages from one. It speaks to brokers by AMQP 1.0, by STOMP and to IBM MQ. What a message queue is for, which brokers fit, and how the connection is written for each, is on [Message queues](Jobs-Messaging.md); this page is the task's form.

## Connection

| Field | What it does |
|---|---|
| **JNDI Config** | the connection, as lines of `name=value`: where the broker is, the user, the password, and which kind of broker. See [how the JMS task knows the broker](Jobs-Messaging.md#how-the-jms-task-knows-the-broker) for the lines of each kind. [Variables](Jobs-Variables.md) work in it. |
| **Destination (Topic or Queue) Name** | the queue or topic |
| **Test Settings** | connects with what is in the form |

## Mode

**Producer** sends. **Consumer** receives.

### Producer

| Field | What it does | On a new task |
|---|---|---|
| **Custom Message** | the message is a text you write | |
| **Message** | the text, with variables: `{"file":"{name}","size":{size}}` | |
| **Text Message** / **Bytes Message** | the kind of message the text is sent as. Most receivers expect a text message. | Text |
| **Loop through items?** | one message per file. Unticked: one message for the run. | off |
| **Send files as messages. (Less than 10 MB)** | in place of a text: each file on the list is sent as a message, its content as the body | |

Under **Advanced options**:

| Field | What it does |
|---|---|
| **Persistent** | the broker keeps the message on disk, so that it survives a restart of the broker |
| **Time to live** | seconds after which an undelivered message is thrown away. 0: never. |
| **Priority** | 0 to 9. Brokers deliver higher ones first. |

A file of 10 MB or more is not sent: "Skip item … as it is greater than 10 MB."

### Consumer

| Field | What it does | On a new task |
|---|---|---|
| **Max messages** | the most messages one run takes | 10 |
| **Read timeout** | milliseconds to wait for a message before the task decides the queue is empty | 1000 |
| **Download messages (Less than 10 MB) here** | the folder each message is saved into, as a file. **Browse**, **Test**. | |
| **File Name** | the name of each saved file, with variables | |

The task takes what is waiting, up to the limit, and ends. An empty queue is not a failure.

## What it hands on

| Mode | The list afterwards |
|---|---|
| Producer | the items it was given |
| Consumer | the items it was given, and one item per message that was saved |

## Examples

**Tell the warehouse system.** Behind a Copy: Producer, **Loop through items?**, the message `{"event":"file.delivered","name":"{name}","at":"{yyyy}-{MM}-{dd}T{HH}:{mm}:{ss}"}`.

**Fetch when told.** A job every minute: Consumer, **Max messages** 1 → a [Jump](Task-Jump.md) on `{items_count}` → on "something came", a Find and a Copy.

## Things to know

- **In the log**, the task lists the settings it connects with, "JMS Config -> …", with passwords masked. That is where a typing mistake in the config shows.
- **Missing files.** The clients for AMQP and IBM MQ are jar files in `plugins/lib` that the server does not bring: see [Files the server needs](Jobs-Messaging.md#files-the-server-needs). An error that names a class that could not be found means one is missing, or the server was not restarted since.
- **A message that was taken is gone from the queue.** If the job fails after taking it, the message is not put back. Save the message first and work on the saved file, so that a failed run can be repeated from the file.
- **Full administrators only**, in the older scheme of admin flags: the task is taken out of a job that a limited admin saves. See [Who may see, change and run a job](Jobs-Access.md).
- **Kafka** has a task of its own: [Kafka](Task-Kafka.md).
