// This module is included in the following assemblies:
// as_connecting-to-amqp.adoc

[id='adding-amqp-connection-middle_{context}']
= Publishing messages to AMQP in the middle of a flow or to finish an integration

You can publish messages to an AMQP broker in the middle of a flow or 
to finish a simple integration. To do this, add an AMQP connection to 
the middle of a flow or as a simple integration's finish connection. 

.Prerequisites
* You created a connection to the AMQP broker that you want to publish 
messages to.
* You are creating or editing a flow and {prodname} is prompting you
to add to the integration. Or, {prodname} is prompting you to choose a 
simple integration's finish connection. 

.Procedure
. On the *Add to Integration* page, click the plus sign where you 
want to add the connection. Skip this step if {prodname} is
prompting you to choose the finish connection. 
. Click the AMQP connection that you want to use to publish messages. 

. On the *Choose an action* page, select one of the following actions:
+
* *Publish messages* to
publish messages to the queue or topic that you specify without receiving
a response. To configure this
action:
.. In the *Destination name* field, enter the name of the queue or 
topic to send messages to. 
.. For the *Destination type*, accept *Queue* or select *Topic*. 
.. Select *Persistent* to guarantee message delivery even if
a connection fails. 
+
* *Request response using messages* to publish messages to the queue or topic 
that you specify and receive a response. 
+
[NOTE]
====
When the finish connection in a simple integration is an AMQP connection 
that performs the *Request response using messages* action, the connection 
publishes the messages but the response is discarded. To avoid losing the 
response, add an AMQP connection as a middle connection that performs 
the *Request response using messages* action and finish the simple integration 
with a log step.
====
+
To configure this action:

.. In the *Destination name* field, enter the name of the queue or topic 
to send messages to. 
.. For the *Destination type*, accept *Queue* or select *Topic*.


.. In the *Durable subscription ID* field, to allow connections to 
close and reopen without missing messages, enter the durable
subscription ID. The destination type must be a topic. 

.. In the *Message selector* field, if you want to receive only responses 
that satisfy a particular condition, enter a filter expression. 
+
A message selector is a string that contains an expression. The syntax of 
the expression is based on a subset of the SQL92 conditional expression syntax. 
The message selector in the following example selects any message that has a 
`NewsType` property whose value is set to `Sports` or `Opinion`:
+
`NewsType = ’Sports’ OR NewsType = ’Opinion’`
+
The message consumer receives only those messages whose headers and 
properties match the message selector expression. A message selector cannot select messages on 
the basis of the content of the message body.

. Click *Next* to specify the action's input and output type. 

. In the *Select Type* field, if the data type does not need to be known, 
accept *Type specification not required* 
and click *Next*. You do not need to follow the rest of these
instructions. 
+
However, a structured data type is recommended. For example, if you want 
to map the connection input/output in a data mapper step then you must specify 
the data type. The data mapper cannot display fields for unstructured data.
+
To specify the data type, click in the *Select Type* field and select one of the following as the schema type:
+
* *JSON schema* is a document that describes the structure of JSON data.
The document's media type is `application/schema+json`. 
* *JSON instance* is a document that contains JSON data. The document's 
media type is `application/json`. 
* *XML schema* is a document that describes the structure of XML data.
The document's file extension is `.xsd`.
* *XML instance* is a document that contains XML data. The
document's file extension is `.xml`. 
* *CSV instance* is a document that contains comma-separated value (CSV) data. The document's file extension is `.csv`. 
ifeval::["{location}" == "downstream"]
+
*Note* _Data Mapper support for CSV data is a Technology Preview feature only._
endif::[]

. In the *Definition* input box, paste a definition that conforms to the
schema type you selected. 
For example, if you select *JSON schema* then you would paste the content of
a JSON schema file, which has a media type of `application/schema+json`.

. In the *Data Type Name* field, enter a name that you choose for the
data type. For example, if you are specifying a JSON schema for vendors 
then you might specify `*Vendor*` as the data type name. 
+
You will see this data type name when you are creating 
or editing an integration that uses the connection
for which you are specifying this type. {prodname} displays the type name
in the integration visualization and in the data mapper. 

. In the *Data Type Description* field, provide information that helps you
distinguish this type. This description appears in the data mapper when 
you hover over the step that processes this type. 
. Click *Next*. 

.Result
The connection appears in the integration visualization where you added it. 
