Thứ Bảy, 16 tháng 4, 2016

Configuring MQ in Anypoint Studio

Configuring MQ in Anypoint Studio

Anypoint Studio MQ Connector

This section describes how to install the Anypoint MQ connector in Anypoint Studio and how to configure Studio to handle applications.
To add the Anypoint MQ connector to Studio:
  1. In Studio, click the X in the upper left of Studio:
    Exchange X icon in the Studio task bar
  2. In Anypoint Exchange, search for anypoint mq:

  3. Click Install.
  4. Type your first and last name, email address, and telephone number. Click the checkbox to agree to the MuleSoft terms of service:
    mq-install-prompt
  5. Click Install.
  6. Follow the prompts to install the Anypoint MQ connector.

Create a Client App

Creating a client app provides the client ID and client secret you can use to register an app as either an Anypoint MQ publisher or subscriber.
  1. In Anypoint Platform, click MQ.
  2. Click Client Apps from the left nav bar:
    mq-client-apps-in-nav.
  3. Click the blue plus circle:
    Create client app circle button about two-thirds to the right below the task bar
  4. Specify the name of the client application.
    mq-create-client-app-window
  5. Click Save Changes.
  6. Click the client app entry to view the client ID and secret values:

  7. Click the Copy button for the ID or secret to copy the value to your computer’s clipboard.
Note: If using the Chrome browser and the Copy buttons don’t function, click Settings > Show advanced settings > Privacy > Content settings > Plugins > Detect and run important plugin content.

Add a Client App to Studio

To add a client app to Studio:
  1. In Anypoint Platform, click MQ > Client Apps:
    mq-client-apps-in-nav
  2. Create a client app. Note the Client ID and Client Secret values. We use these later when we configure the Anypoint MQ connector in Anypoint Studio.
  3. In Studio, click File > New > Mule Project.
  4. Search for "http" and drag the HTTP connector to the Studio Canvas. Click the HTTP connector, and click the green plus sign to the right of Connector Configuration. Click OK to accept the defaults.
  5. Search for "mq" and drag the Anypoint MQ connector to the canvas.
  6. Click the green plus sign to the right of Connector Configuration.
  7. In the Global Element Properties window:
    1. Copy the Anypoint Platform > MQ > Client App > Client App ID value to Studio’s Client ID field.
    2. Copy the Client App > Client Secret value to Studio’s Client Secret field. You can ignore the other settings to test your first connector.
    3. Set Max Redelivery to -1 to ensure that Anypoint MQ keeps retrying to deliver a message that is not delivered. The -1 value indicates that there is no limit to retries.
      mq-set-max-redelivery
      If you want to set the remaining fields or tabs, see Advanced Global Element Properties.
    4. Click OK.
  8. Click the Operation field and specify an operation such as Publish or Consume.
  9. Specify the Destination as the name of the Queue or Exchange that you set in Anypoint Platform.

Example Studio Flow

The flow for the previous Anypoint Studio example is as follows:

          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
        xmlns:anypoint-mq="http://www.mulesoft.org/schema/mule/anypoint-mq" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/anypoint-mq http://www.mulesoft.org/schema/mule/anypoint-mq/current/mule-anypoint-mq.xsd">
  <anypoint-mq:config name="Anypoint_MQ_Configuration" doc:name="Anypoint MQ Configuration">
      <anypoint-mq:provider url="https://mq-us-east-1.anypoint.mulesoft.com/api/v1" clientId="<id>" clientSecret="<secret>"/>
  </anypoint-mq:config>
<flow name="producerFlow">
  <poll doc:name="Poll">
    <dw:transform-message doc:name="Create Customer">
    <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
    "firstName" : "Joe",
    "lastName" : "Schmoe",
    "company" : "Acme, Inc"
}]]></dw:set-payload>
    </dw:transform-message>
  </poll>
        <anypoint-mq:publish config-ref="Anypoint_MQ_Configuration" destination="MyExchange" doc:name="Anypoint MQ">
            <anypoint-mq:message-builder messageId="mq42"/>
        </anypoint-mq:publish>
</flow>
</mule>

Advanced Global Element Properties

This section provides information about all the Global Element Properties screens.

General Tab


The General tab fields are:
Field Req’d Default Description
Use Global Provider Config
no
none
Makes provider configuration available to all applications.
Provider
yes
none
(Required if you choose Use Global Provider Config) - Lists the name Provider_Settings after you specify the client ID and client secret to use for all applications. Provider is a container for required attributes that identifies the Anypoint MQ broker access (URL, client ID, and Client Secret) values.
Max Redelivery
no
-1
Number of redeliveries to try in case a message fails. -1 indicates that Anypoint MQ retry indefinitely.
Acknowledgement Mode
no
none
Defines how the Anypoint MQ messages are acknowledged when the message are removed from being inflight messages. Possible values are:
  • NONE - Messages are removed as soon as they are read
  • AUTO - Messages are removed when the message flow is completed
  • MANUAL - Messages should be removed manually using a custom ACK message processor.
Acknowledgement Timeout
no
none
When you take an Anypoint MQ message from a queue, the broker puts it in flight, and the message remains in that state until the ACK is performed (application reads the message and Anypoint MQ deletes it), or the Acknowledgement Timeout is reached. If ACK is performed, then the message is removed from the queue, if Acknowledgement Timeout is reached, the message returns to the queue.
Use default worker threading profile
no
none
See Tuning Performance. The threading profile options let you optimize connector performance for use with Anypoint MQ.
Use custom worker threading profile
no
none
Max Active Threads
no
none
Thread TTL
no
none
Thread time to live duration.
Pool Exhausted Action
no
none
Pool exhausted action.
Thread Wait Timeout
no
none
Thread wait timeout in milliseconds.
Max Buffer Size
no
none
Max buffer size.

TLS/SSL and Proxy Tabs

The TSL/SSL and Proxy tabs share the same information as the HTTP Connector.

Prefetch Tab

Number of messages to receive at once when asking for messages. The response can contain fewer messages than this number depending of the poolingTime set.
When you subscribe a flow to an Anypoint MQ queue, the flow pool regularly the queue looking for messages. This operation can be very time consuming. In order to avoid delays, prefetch was introduced. This is a component placed between the flow and the Anypoint MQ queue that polls the queue regularly, but without processing the pooled messages. You can change these values depending on your site’s performance and use case needs.
mq-prefetch-general
The Prefetch tab fields are:
Value Description
Fetch Size
Number of messages to prefetch.
Fetch Timeout
Maximum duration in milliseconds to wait for the required amount of messages. When this time elapses, the response is sent with as many messages as taken during the period.
Frequency
The duration in milliseconds to execute the retrieve operation when the prefetch queue is not empty.
Note: For best performance, set Fetch Size to 10 (maximum value) and reduce Frequency to increase the pooling time and the resulting dequeuing of transactions per second (TPS). You can increase Fetch Timeout if message processing is slow. For example, if processing takes 5 seconds, set the Fetch Timeout to at least double this time (10000 milliseconds).
Apart from these performance-related parameters, it is important to properly configure the Acknowledgement Mode.

3 nhận xét: