# eb-event-streaming

Part of **EB**

<!-- intent-backlink:auto -->

> 💡 **Path Selection**: This skill is one implementation path for [Configure real-time event streaming](../../intent/eb-configure-streaming/SKILL.md). If you're unsure which path to take, check the routing skill first.

# EventBridge Event Streaming

## Capabilities Overview

| Sub-capability | Calling Mode | Description |
|----------------|--------------|-------------|
| Create Event Streaming | Synchronous | API reference for creating an event streaming in EventBridge, specifying source and sink configurations with detailed parameters for various data sources and targets. |
| Delete Event Stream | Synchronous | Deletes an event stream in EventBridge. This API allows users to remove a specified event stream by providing its name. |
| Pause Event Streaming | Synchronous | This document describes the PauseEventStreaming API operation, which stops an active event stream in Alibaba Cloud EventBridge. |
| Enable Event Stream | Synchronous | Enables a created or deactivated event stream in EventBridge. This API operation allows users to activate an existing event stream for event processing. |
| List Event Streamings | Synchronous | Queries information about all created event streams in EventBridge, including stream details, source and sink configurations, status, and runtime options. |
| Get Event Streaming Details | Synchronous | Queries the details of an event stream in EventBridge, including its status, source configuration, sink settings, and run options. |
| Update Event Streaming Configuration | Synchronous | Modifies the information about event streams, including basic details and configurations for event sources, rules, and targets. |
| Stream Events | Synchronous | This document provides reference information for EventStreamings, a feature within the EventBridge service that enables real-time event streaming and processing. |
| Update Event Stream Configuration | Synchronous | Updates the billing method, compute unit (CU) resources, and other configurations of an event stream in EventBridge. |
| Configure RabbitMQ Source for Event Streaming | Synchronous | Configures an ApsaraMQ for RabbitMQ message source in an EventBridge event streaming task. |

## API Calling Patterns

### Authentication
The primary authentication method is Bearer Token authentication.
- Use the header format: `Authorization: Bearer <your_api_key>`
- Set the environment variable: `DASHSCOPE_API_KEY`
- Some endpoints use Alibaba Cloud Signature authentication (`Authorization: acs <AccessKeyID>:<Signature>`) but Bearer Token is recommended for most use cases.

### Service Endpoint
EventBridge Event Streaming APIs use region-specific endpoints with the pattern:
`https://{account_id}.eventbridge.{region}.aliyuncs.com`

Common regions include:
- cn-hangzhou
- cn-shanghai  
- cn-beijing

Some international endpoints follow the pattern: `https://api.alibabacloud.com/api/eventbridge/2020-04-01/{Operation}`

### Synchronous API Pattern
All EventBridge Event Streaming operations follow a synchronous calling pattern:
1. Send a POST request to the appropriate endpoint with JSON payload
2. Include required authentication headers
3. Receive immediate JSON response with operation result
4. Parse the response for success/failure status and relevant data

The typical request flow includes:
- Setting proper Content-Type header (`application/json;charset=UTF-8`)
- Including version header (`x-eventbridge-version: 2020-04-01`)
- Providing required parameters in the JSON body
- Handling the synchronous response with RequestId, Code, and Success fields

## Parameter Reference

### Create Event Streaming

| Parameter | Type | Required | Default | Constraints | Description |
|-----------|------|----------|---------|-------------|-------------|
| EventStreamingName | string | true | | | Name of the event stream. |
| Description | string | false | | | Description of the event stream. |
| FilterPattern | string | true | | | Event filtering rule. If not specified, all events are matched. |
| Source | object | true | | | Event source. Only one type allowed. |
| Sink | object | true | | | Target service. Only one type allowed. |

### Update Event Streaming Configuration

| Parameter | Type | Required | Default | Constraints | Description |
|-----------|------|----------|---------|-------------|-------------|
| EventStreamingName | string | true | | | The name of the event stream to be updated. |
| Description | string | false | | | A description of the event stream. |
| FilterPattern | string | false | {} | | The filter pattern used to determine which events are processed by the event stream. |
| Source | object | true | | | Configuration for the event source, including specific parameters based on the source type. |
| Sink | object | true | | | Configuration for the event target, including specific parameters based on the sink type. |
| RunOptions | object | false | | | Options for running the event stream, such as error tolerance and retry strategy. |

### Configure RabbitMQ Source for Event Streaming

| Parameter | Type | Required | Default | Constraints | Description |
|-----------|------|----------|---------|-------------|-------------|
| InstanceType | string | false | | | The type of the ApsaraMQ for RabbitMQ instance. |
| InstanceId | string | false | | | The ID of the ApsaraMQ for RabbitMQ instance. |
| Endpoint | string | false | | | The endpoint used to connect to the ApsaraMQ for RabbitMQ instance. |
| VirtualHostName | string | false | | | The vhost name on the ApsaraMQ for RabbitMQ instance. |
| OrderConsume | string | false | | one of: true, false | Specifies whether to consume messages in strict order. Enabling ordered consumption may reduce throughput. |
| BodyDataType | string | false | | one of: JSON, TEXT, BINARY | The deserialization format for the message body. |
| PrefetchCount | string | false | 100 | range: 1-1000 | The maximum number of unacknowledged messages that the consumer can receive at a time. |
| Username | string | false | | | The username used to access the ApsaraMQ for RabbitMQ instance. |
| Password | string | false | | | The password used to access the ApsaraMQ for RabbitMQ instance. |
| VpcId | string | false | | | The ID of the Virtual Private Cloud (VPC) in which the ApsaraMQ for RabbitMQ instance resides. |
| VSwitchIds | string | false | | | The vSwitch ID in the VPC. |
| SecurityGroupId | string | false | | | The security group ID in the VPC. |
| NetworkType | string | false | | one of: PublicNetwork, PrivateNetwork | The network type used to connect to the ApsaraMQ for RabbitMQ instance. |

### Update Event Stream Configuration (Business Options)

| Parameter | Type | Required | Default | Constraints | Description |
|-----------|------|----------|---------|-------------|-------------|
| EventStreamingName | string | true | | | The name of the event stream. |
| BusinessMode | string | true | | one of: CapacityUnitMode, EventNumMode | The billing mode. Valid values are CapacityUnitMode for the CU mode and EventNumMode for the pay-by-event mode. |
| MinCapacityUnitCount | integer | false | | range 1-999 | The minimum number of CUs. |
| MaxCapacityUnitCount | integer | false | | range 1-999 | The maximum number of CUs. |

## Code Examples

### Create Event Streaming - Python - International

```python
import requests

url = "https://api.aliyun.com/api/eventbridge/2020-04-01/CreateEventStreaming"
headers = {
    "Authorization": "Bearer $DASHSCOPE_API_KEY",
    "Content-Type": "application/json"
}

payload = {
    "EventStreamingName": "myeventstreaming",
    "Description": "rocketmq2mns",
    "FilterPattern": "{\"source\": [{\"prefix\": \"acs:mns\"}], \"type\": [{\"prefix\": \"mns:Queue\"}], \"subject\": [{\"prefix\": \"acs:mns:cn-hangzhou:123456789098****:queues/zeus\"}]}",
    "Source": {
        "SourceMNSParameters": {
            "RegionId": "cn-beijing",
            "QueueName": "queue_api_1642474203601",
            "IsBase64Decode": True
        }
    },
    "Sink": {
        "SinkMNSParameters": {
            "QueueName": {
                "Value": "MyQueue",
                "Form": "CONSTANT",
                "Template": "The value of ${key} is ${value}!"
            },
            "Body": {
                "Value": "{\"key\": \"value\"}",
                "Form": "TEMPLATE",
                "Template": "The value of ${key} is ${value}!"
            },
            "IsBase64Encode": {
                "Value": "true",
                "Form": "CONSTANT",
                "Template": "The value of ${key} is ${value}!"
            }
        }
    }
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

### Create Event Streaming - Bash - China

```bash
POST /eventstreaming/creatEventStreaming HTTP/1.1
Host: 164901546557****.eventbridge.cn-hangzhou.aliyuncs.com
Date: Sat, 18 Apr 2020 05:30:41 GMT
x-eventbridge-version: 2020-04-01
Authorization: acs vZ3VL0SuJdHi****:Jo2PbT******azYAYoYslKLvWzg=
Content-Type: application/json;charset=UTF-8
Content-Length: 26

{
    "EventStreamingName":"myeventstreaming",
    "Description":"rocketmq2mns",
    "FilterPattern":"{}",
    "Source":{
        "SourceRocketMQParameters":{
            "InstanceId":"MQ_INST_164901546557****_BAAN****",
            "GroupID":"GID_group1",
            "Topic":"mytopic",
            "Offset":"CONSUME_FROM_TIMESTAMP",
            "Tag":"",
            "RegionId":"cn-hangzhou",
            "Timestamp":1636597951964
        }
    },
    "Sink":{
        "SinkMNSParameters":{
            "QueueName":{
                "Value":"MyQueue",
                "Form":"CONSTANT"
            },
            "IsBase64Encode":{
                "Value":"true",
                "Form":"CONSTANT"
            },
            "Body":{
                "Value":{
                    "key":"value"
                },
                "Form":"TEMPLATE",
                "Template":"The value of ${key} is ${value}!"
            }
        }
    },
    "RunOptions":{
        "ErrorsTolerance":"ALL",
        "RetryStrategy":{
            "PushRetryStrategy":"BACKOFF_RETRY"
        },
        "DeadLetterQueue":{
            "Arn":"acs:mq:cn-chengdu:164901546557****:/instances/MQ_INST_164901546557****_BXxk0KXx/topic/Mytopic"
        }
    }
}
```

### Delete Event Stream - Bash - All Regions

```bash
POST /eventstreaming/deleteEventStreaming HTTP/1.1
Host: 164901546557****.eventbridge.cn-hangzhou.aliyuncs.com
Date: Sat, 18 Apr 2020 05:30:41 GMT
x-eventbridge-version: 2020-04-01
Authorization: acs vZ3VL0SuJdHi****:Jo2PbT******azYAYoYslKLvWzg=
Content-Type: application/json;charset=UTF-8
Content-Length: 26

{
    "EventStreamingName":"myeventstreaming"
}
```

### Configure RabbitMQ Source - Python - All Regions

```python
import dashscope

dashscope.api_key = 'your-api-key'

source_config = {
    "InstanceType": "Standard",
    "InstanceId": "gtm-cn-k2c2yfg****",
    "Endpoint": "amqp://your-endpoint",
    "VirtualHostName": "eb-connect",
    "OrderConsume": "true",
    "BodyDataType": "JSON",
    "PrefetchCount": "100",
    "Username": "admin",
    "Password": "your-password",
    "NetworkType": "PrivateNetwork",
    "VpcId": "vpc-8vblalsi0vbhizr77****",
    "VSwitchIds": "vsw-bp179l3llg3jjxwrq72****",
    "SecurityGroupId": "sg-bp1iv19sp1msc7zot4****"
}

response = dashscope.EventBridge.create_event_streaming(
    source=source_config,
    target={"Type": "Kafka", "Endpoint": "kafka://your-kafka-endpoint"}
)

print(response)
```

### Update Event Streaming Configuration - Bash - China

```bash
POST /eventstreaming/updateEventStreaming HTTP/1.1
Host: 164901546557****.eventbridge.cn-hangzhou.aliyuncs.com
Date: Sat, 18 Apr 2020 05:30:41 GMT
x-eventbridge-version: 2020-04-01
Authorization: acs vZ3VL0SuJdHi****:Jo2PbT******azYAYoYslKLvWzg=
Content-Type: application/json;charset=UTF-8
Content-Length: 26

{
    "EventStreamingName":"myeventstreaming",
    "Description":"rocketmq2rabbitmq",
    "FilterPattern":"{}",
    "Source":{
        "SourceRocketMQParameters":{
            "InstanceId":"MQ_INST_164901546557****_BAAN****",
            "GroupID":"GID_group1",
            "Topic":"mytopic",
            "Offset":"CONSUME_FROM_LAST_OFFSET",
            "Tag":"",
            "RegionId":"cn-hangzhou"
        }
    },
    "Sink":{
        "SinkRabbitMQParameters":{
            "InstanceId":{
                "Value":"amqp-cn-2r42e73o****",
                "Form":"CONSTANT"
            },
            "VirtualHostName":{
                "Value":"dlq",
                "Form":"CONSTANT"
            },
            "TargetType":{
                "Value":"Exchange",
                "Form":"CONSTANT"
            },
            "Exchange":{
                "Value":"a_exchange",
                "Form":"CONSTANT"
            },
            "RoutingKey":{
                "Value":"housekeeping",
                "Form":"JSONPATH"
            },
            "Body":{
                "Value":"{\n  \"key\": \"value\"\n}",
                "Form":"TEMPLATE",
                "Template":"The value of ${key} is ${value}."
            },
            "MessageId":{
                "Value":"message_001",
                "Form":"JSONPATH"
            },
            "Properties":{
                "Value":"systemProperties",
                "Form":"JSONPATH"
            }
        }
    },
    "RunOptions":{
        "ErrorsTolerance":"ALL",
        "RetryStrategy":{
            "PushRetryStrategy":"BACKOFF_RETRY"
        }
    }
}
```

### Get Event Streaming Details - Bash - China

```bash
POST /eventstreaming/getEventStreaming HTTP/1.1
Host: 164901546557****.eventbridge.cn-hangzhou.aliyuncs.com
Date: Sat, 18 Apr 2020 05:30:41 GMT
x-eventbridge-version: 2020-04-01
Authorization: acs vZ3VL0SuJdHi****:Jo2PbT******azYAYoYslKLvWzg=
Content-Type: application/json;charset=UTF-8
Content-Length: 26

{
    "EventStreamingName":"myeventstreaming"
}
```

## Response Format

```json
{
    "code":"200",
    "data":{
        "RequestId":"244BED53-719A-15D7-B7F9-1C404273****",
        "Data":{
            "EventStreamingARN":"acs:eventbridge:cn-hangzhou:164901546557****:eventstreaming/myeventstreaming"
        },
        "Code":"Success",
        "Success":true
    },
    "httpStatusCode":"200",
    "requestId":"244BED53-719A-15D7-B7F9-1C404273****",
    "successResponse":true
}
```

**Key Fields**:
- `data.EventStreamingARN` — The Alibaba Cloud Resource Name (ARN) of the created event stream
- `requestId` — Unique identifier for the API request
- `data.RequestId` — Alternative request identifier in some response formats
- `data.Success` — Boolean indicating if the operation succeeded
- `data.Code` — Status code of the operation ("Success" for successful operations)

## Error Handling

| Error Code | Description | Recommended Action |
|------------|-------------|-------------------|
| 400 | The service is not enabled. Ensure the EventBridge service is enabled in your account. | Activate the EventBridge service in your Alibaba Cloud account |
| 400 | Bad request. Check the request parameters for syntax or validation errors. | Verify all required parameters are provided and formatted correctly |
| 403 | Forbidden. The request is not authorized. Verify your API key or permissions. | Check your API key and ensure your account has proper permissions |
| 403 | ServiceNotEnable: The service is not enabled. Ensure that the EventBridge service is activated in your account. | Enable the EventBridge service in your Alibaba Cloud console |
| 404 | Not Found: The specified EventStreaming does not exist. | Verify the event stream name exists in your account and region |
| 429 | Too many requests. Rate limiting has been triggered. Wait and retry later. | Implement exponential backoff and respect rate limits |
| 500 | Internal server error. Retry the request after a delay. | Retry the request with exponential backoff |

### Rate Limits & Retry
- Standard operations: 100 QPS per account
- RabbitMQ source configuration: 100 requests per minute per account
- Free tier operations: 100-1000 requests per minute depending on operation type

Recommended retry strategy:
- Use exponential backoff with jitter
- Start with 1-second delay, double on each retry up to 30 seconds
- Limit total retry attempts to 5-10 based on operation criticality
- For 429 errors, respect any Retry-After header if present

## Requirements

- For RabbitMQ source configuration: `dashscope>=1.14.0`
- Environment variable setup: `export DASHSCOPE_API_KEY=your_api_key_here`
- Standard HTTP client library capable of sending JSON payloads with custom headers

## FAQ

Q: How do I authenticate my EventBridge Event Streaming API requests?
A: Use Bearer Token authentication with the header `Authorization: Bearer $DASHSCOPE_API_KEY` where DASHSCOPE_API_KEY is your API key stored as an environment variable. Some legacy endpoints may require Alibaba Cloud Signature authentication instead.

Q: What source and sink types are supported for event streaming?
A: EventBridge supports multiple source and sink types including RocketMQ, MNS (Message Service), RabbitMQ, and Log Service (SLS). Each requires specific parameter configurations documented in the API reference.

Q: How are failed event deliveries handled in EventBridge event streams?
A: EventBridge uses retry policies (default: BACKOFF_RETRY), fault tolerance policies (default: ALL), and optional dead-letter queues (DLQs) to handle delivery failures. Failed events that exhaust retries can be sent to a DLQ for later analysis.

Q: What are the two billing methods available for event streams?
A: Event streams support two billing methods: CapacityUnitMode (billing based on reserved Compute Units) and EventNumMode (pay-per-event). You can switch between these modes using the UpdateEventStreamingBusinessOption API.

Q: How do I filter events in my event stream?
A: Use the FilterPattern parameter with JSON-based event patterns to specify which events should be processed. Patterns support field value matching, prefix/suffix matching, numeric ranges, IP address matching, and combined conditions.

## Pricing & Billing

### Billing Model
Per-request billing model where each API call (create, delete, update, etc.) counts as one request regardless of success or failure.

### Price Reference

| Tier | Input Price | Output Price |
|------|-------------|--------------|
| standard | 0.002 / | 0.003 / |
| default | 0.001 / | 0.002 / |
| default | 0.0001 / | 0.0001 / |

### Free Tier
- Monthly free quotas ranging from 100 to 10,000 requests depending on the specific operation
- Free tier resets monthly

### Usage Limits
- Single request maximum: 8192-100KB characters/data depending on operation
- Rate limits: 10-100 QPS per account depending on operation type
- RabbitMQ source: Maximum 1000 messages per request, 100 requests per minute

### Billing Notes
- Each API call counts as one request for billing purposes
- Async operations may incur additional charges based on duration
- Billing is based on actual usage with no minimum fees
- Free tier allowances vary by operation type