You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/catalog.md
+113-1
Original file line number
Diff line number
Diff line change
@@ -627,7 +627,119 @@ The `/whisk.system/watson-speechToText/speechToText` action converts audio speec
627
627
}
628
628
```
629
629
630
-
630
+
## Using the Message Hub package
631
+
632
+
This package allows you to create triggers that react when messages are posted to a [Message Hub](https://developer.ibm.com/messaging/message-hub/) service instance on Bluemix.
633
+
634
+
### Creating a Trigger that listens to a Message Hub Instance
635
+
In order to create a trigger that reacts when messages are posted to a Message Hub instance, you need to use the feed named `messaging/messageHubFeed`. This feed supports the following parameters:
636
+
637
+
|Name|Type|Description|
638
+
|---|---|---|
639
+
|kafka_brokers_sasl|JSON Array of Strings|This parameter is an array of `<host>:<port>` strings which comprise the brokers in your Message Hub instance|
640
+
|user|String|Your Message Hub user name|
641
+
|password|String|Your Message Hub password|
642
+
|topic|String|The topic you would like the trigger to listen to|
643
+
|kafka_admin_url|URL String|The URL of the Message Hub admin REST interface|
644
+
|api_key|String|Your Message Hub API key|
645
+
|isJSONData|Boolean (Optional - default=false)|When set to `true` this will cause the feed to try to parse the message content as JSON before passing it along as the trigger payload.|
646
+
647
+
While this list of parameters may seem daunting, they can be automatically set for you by using the package refresh CLI command:
648
+
649
+
1. Create an instance of Message Hub service under your current organization and space that you are using for OpenWhisk.
650
+
651
+
2. Verify that the the topic you want to listen it already exists in Message Hub or create a new topic to listen for messages, like `mytopic`.
652
+
653
+
2. Refresh the packages in your namespace. The refresh automatically creates a package binding for the Message Hub service instance that you created.
### Setting up a Message Hub package outside Bluemix
680
+
681
+
If you're not using OpenWhisk in Bluemix or if you want to set up your Message Hub outside of Bluemix, you must manually create a package binding for your Message Hub service. You need the Message Hub service credentials and connection information.
682
+
683
+
- Create a package binding that is configured for your Message Hub service.
### Listening for messages to a Message Hub instance
690
+
After creating a trigger, the system will monitor the specified topic in your messaging service. When new messages are posted, the trigger will be fired.
691
+
692
+
The payload of that trigger will contain a `messages` field which is an array of messages that have been posted since the last time your trigger fired. Each message object in the array will contain the following fields:
693
+
- topic
694
+
- partition
695
+
- offset
696
+
- key
697
+
- value
698
+
699
+
In Kafka terms, these fields should be self-evident. However, the `value` requires special consideration. If the `isJSONData` parameter was set `false` (or not set at all) when the trigger was created, the `value` field will be the raw value of the posted message. However, if `isJSONData` was set to `true` when the trigger was created, the system will attempt to parse this value as a JSON object, on a best-effort basis. If parsing is successful, then the `value` in the trigger payload will be the resulting JSON object.
700
+
701
+
For example, if a message of `{"title": "Some string", "amount": 5, "isAwesome": true}` is posted with `isJSONData` set to `true`, the trigger payload might look something like this:
702
+
703
+
```JSON
704
+
{
705
+
"messages": [
706
+
{
707
+
"partition": 0,
708
+
"key": null,
709
+
"offset": 421760,
710
+
"topic": "mytopic",
711
+
"value": {
712
+
"amount": 5,
713
+
"isAwesome": true,
714
+
"title": "Some string"
715
+
}
716
+
}
717
+
]
718
+
}
719
+
```
720
+
721
+
However, if the same message content is posted with `isJSONData` set to `false`, the trigger payload would look like this:
You will notice that the trigger payload contains an array of messages. This means that if you are producing messages to your messaging system very quickly, the feed will attempt to batch up the posted messages into a single firing of your trigger. This allows the messages to be posted to your trigger more rapidly and efficiently.
739
+
740
+
Please keep in mind when coding actions that are fired by your trigger, that the number of messages in the payload is technically unbounded, but will always be greater than 0.
741
+
742
+
631
743
## Using the Slack package
632
744
633
745
The `/whisk.system/slack` package offers a convenient way to use the [Slack APIs](https://api.slack.com/).
0 commit comments