|
| 1 | +--- |
| 2 | +type: docs |
| 3 | +title: "Apache RocketMQ binding spec" |
| 4 | +linkTitle: "RocketMQ" |
| 5 | +description: "Detailed documentation on the Apache RocketMQ binding component" |
| 6 | +aliases: |
| 7 | + - "/operations/components/setup-bindings/supported-bindings/rocketmq/" |
| 8 | +--- |
| 9 | + |
| 10 | + |
| 11 | +## Component format |
| 12 | + |
| 13 | +To set up an Apache RocketMQ binding, create a component of type `bindings.rocketmq`. |
| 14 | +See [this guide]({{% ref "howto-bindings.md#1-create-a-binding" %}}) on how to create and apply a binding configuration. |
| 15 | + |
| 16 | +```yaml |
| 17 | +apiVersion: dapr.io/v1alpha1 |
| 18 | +kind: Component |
| 19 | +metadata: |
| 20 | + name: <NAME> |
| 21 | +spec: |
| 22 | + type: bindings.rocketmq |
| 23 | + version: v1 |
| 24 | + metadata: |
| 25 | + - name: accessProto |
| 26 | + value: "tcp" |
| 27 | + - name: nameServer |
| 28 | + value: "localhost:9876" |
| 29 | + - name: endpoint |
| 30 | + value: "http://localhost:8080" |
| 31 | + - name: topics |
| 32 | + value: "topic1,topic2" |
| 33 | + - name: consumerGroup |
| 34 | + value: "my-consumer-group" |
| 35 | + # Optional |
| 36 | + - name: consumerBatchSize |
| 37 | + value: "10" |
| 38 | + - name: consumerThreadNums |
| 39 | + value: "4" |
| 40 | + - name: retries |
| 41 | + value: "3" |
| 42 | + - name: instanceId |
| 43 | + value: "my-instance" |
| 44 | +```` |
| 45 | + |
| 46 | +{{% alert title="Warning" color="warning" %}} |
| 47 | +The above example uses secrets as plain strings. |
| 48 | +It is recommended to use a secret store for the secrets as described [here]({{% ref component-secrets.md %}}). |
| 49 | +{{% /alert %}} |
| 50 | + |
| 51 | +## Spec metadata fields |
| 52 | + |
| 53 | +| Field | Required | Binding support | Details | Example | |
| 54 | +| -------------------- | :------: | --------------- | --------------------------------------------------------------------- | ------------------------------ | |
| 55 | +| `topics` | Y | Input/Output | Comma-separated list of topics for publishing or subscribing. | `"topic1,topic2"` | |
| 56 | +| `nameServer` | N | Input/Output | Address of the RocketMQ name server. | `"localhost:9876"` | |
| 57 | +| `endpoint` | N | Input/Output | RocketMQ endpoint (for `http` protocol). | `"http://localhost:8080"` | |
| 58 | +| `accessProto` | N | Input/Output | SDK protocol for connecting to RocketMQ. | `"tcp"`, `"tcp-cgo"`, `"http"` | |
| 59 | +| `consumerGroup` | N | Input/Output | Consumer group name for RocketMQ subscribers. | `"my-consumer-group"` | |
| 60 | +| `consumerBatchSize` | N | Input | Batch size for consuming messages. | `"10"` | |
| 61 | +| `consumerThreadNums` | N | Input | Number of consumer threads (for `tcp-cgo` protocol). | `"4"` | |
| 62 | +| `instanceId` | N | Input/Output | RocketMQ namespace instance ID. | `"my-instance"` | |
| 63 | +| `nameServerDomain` | N | Input/Output | Domain name for the RocketMQ name server. | `"rocketmq.example.com"` | |
| 64 | +| `retries` | N | Input/Output | Number of retry attempts to connect to the RocketMQ broker. | `"3"` | |
| 65 | +| `accessKey` | N | Input/Output | Access key for authentication. Required if access control is enabled. | `"access-key"` | |
| 66 | +| `secretKey` | N | Input/Output | Secret key for authentication. Required if access control is enabled. | `"secret-key"` | |
| 67 | + |
| 68 | +> **Note**: `accessKey` and `secretKey` can be stored in a Dapr secret store instead of the YAML file for improved security. |
| 69 | + |
| 70 | +### Authentication Using Access Keys |
| 71 | + |
| 72 | +To use access key authentication, include the following metadata fields in the configuration: |
| 73 | + |
| 74 | +```yaml |
| 75 | +- name: accessKey |
| 76 | + secretKeyRef: |
| 77 | + name: rocketmq-secrets |
| 78 | + key: accessKey |
| 79 | +- name: secretKey |
| 80 | + secretKeyRef: |
| 81 | + name: rocketmq-secrets |
| 82 | + key: secretKey |
| 83 | +``` |
| 84 | + |
| 85 | +This allows secure retrieval of credentials from a secret store. |
| 86 | + |
| 87 | +## Binding support |
| 88 | + |
| 89 | +This component supports both **input and output** binding interfaces. |
| 90 | + |
| 91 | +This component supports **output binding** with the following operations: |
| 92 | + |
| 93 | +* `create`: publishes a new message |
| 94 | +* `read`: consumes messages from RocketMQ topics |
| 95 | + |
| 96 | +## Set topic per-request |
| 97 | + |
| 98 | +You can override the topic in component metadata on a per-request basis: |
| 99 | + |
| 100 | +```json |
| 101 | +{ |
| 102 | + "operation": "create", |
| 103 | + "metadata": { |
| 104 | + "topics": "dynamicTopic" |
| 105 | + }, |
| 106 | + "data": "This is a test message for RocketMQ!" |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +## Retry behavior |
| 111 | + |
| 112 | +Use the `retries` metadata field to specify how many times Dapr should attempt to connect to RocketMQ before failing: |
| 113 | + |
| 114 | +```yaml |
| 115 | +- name: retries |
| 116 | + value: "5" |
| 117 | +``` |
| 118 | + |
| 119 | +## Related links |
| 120 | + |
| 121 | +- [Basic schema for a Dapr component]({{% ref component-schema %}}) |
| 122 | +- [Bindings building block]({{% ref bindings %}}) |
| 123 | +- [How-To: Trigger application with input binding]({{% ref howto-triggers.md %}}) |
| 124 | +- [How-To: Use bindings to interface with external resources]({{% ref howto-bindings.md %}}) |
| 125 | +- [Bindings API reference]({{% ref bindings_api.md %}}) |
0 commit comments