[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-a9877139-49b1-4a93-89c6-19801a59af8d":3,"$f8yBLCTPL2dNNIRv9qclfTlGocoQI86qnxz6IqD9H1Kw":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"a9877139-49b1-4a93-89c6-19801a59af8d","azure-eventhub-ts","高吞吐量事件流和实时数据摄取。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-eventhub-ts\ndescription: \"High-throughput event streaming and real-time data ingestion.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Azure Event Hubs SDK for TypeScript\n\nHigh-throughput event streaming and real-time data ingestion.\n\n## Installation\n\n```bash\nnpm install @azure\u002Fevent-hubs @azure\u002Fidentity\n```\n\nFor checkpointing with consumer groups:\n```bash\nnpm install @azure\u002Feventhubs-checkpointstore-blob @azure\u002Fstorage-blob\n```\n\n## Environment Variables\n\n```bash\nEVENTHUB_NAMESPACE=\u003Cnamespace>.servicebus.windows.net\nEVENTHUB_NAME=my-eventhub\nSTORAGE_ACCOUNT_NAME=\u003Cstorage-account>\nSTORAGE_CONTAINER_NAME=checkpoints\n```\n\n## Authentication\n\n```typescript\nimport { EventHubProducerClient, EventHubConsumerClient } from \"@azure\u002Fevent-hubs\";\nimport { DefaultAzureCredential } from \"@azure\u002Fidentity\";\n\nconst fullyQualifiedNamespace = process.env.EVENTHUB_NAMESPACE!;\nconst eventHubName = process.env.EVENTHUB_NAME!;\nconst credential = new DefaultAzureCredential();\n\n\u002F\u002F Producer\nconst producer = new EventHubProducerClient(fullyQualifiedNamespace, eventHubName, credential);\n\n\u002F\u002F Consumer\nconst consumer = new EventHubConsumerClient(\n  \"$Default\", \u002F\u002F Consumer group\n  fullyQualifiedNamespace,\n  eventHubName,\n  credential\n);\n```\n\n## Core Workflow\n\n### Send Events\n\n```typescript\nconst producer = new EventHubProducerClient(namespace, eventHubName, credential);\n\n\u002F\u002F Create batch and add events\nconst batch = await producer.createBatch();\nbatch.tryAdd({ body: { temperature: 72.5, deviceId: \"sensor-1\" } });\nbatch.tryAdd({ body: { temperature: 68.2, deviceId: \"sensor-2\" } });\n\nawait producer.sendBatch(batch);\nawait producer.close();\n```\n\n### Send to Specific Partition\n\n```typescript\n\u002F\u002F By partition ID\nconst batch = await producer.createBatch({ partitionId: \"0\" });\n\n\u002F\u002F By partition key (consistent hashing)\nconst batch = await producer.createBatch({ partitionKey: \"device-123\" });\n```\n\n### Receive Events (Simple)\n\n```typescript\nconst consumer = new EventHubConsumerClient(\"$Default\", namespace, eventHubName, credential);\n\nconst subscription = consumer.subscribe({\n  processEvents: async (events, context) => {\n    for (const event of events) {\n      console.log(`Partition: ${context.partitionId}, Body: ${JSON.stringify(event.body)}`);\n    }\n  },\n  processError: async (err, context) => {\n    console.error(`Error on partition ${context.partitionId}: ${err.message}`);\n  },\n});\n\n\u002F\u002F Stop after some time\nsetTimeout(async () => {\n  await subscription.close();\n  await consumer.close();\n}, 60000);\n```\n\n### Receive with Checkpointing (Production)\n\n```typescript\nimport { EventHubConsumerClient } from \"@azure\u002Fevent-hubs\";\nimport { ContainerClient } from \"@azure\u002Fstorage-blob\";\nimport { BlobCheckpointStore } from \"@azure\u002Feventhubs-checkpointstore-blob\";\n\nconst containerClient = new ContainerClient(\n  `https:\u002F\u002F${storageAccount}.blob.core.windows.net\u002F${containerName}`,\n  credential\n);\n\nconst checkpointStore = new BlobCheckpointStore(containerClient);\n\nconst consumer = new EventHubConsumerClient(\n  \"$Default\",\n  namespace,\n  eventHubName,\n  credential,\n  checkpointStore\n);\n\nconst subscription = consumer.subscribe({\n  processEvents: async (events, context) => {\n    for (const event of events) {\n      console.log(`Processing: ${JSON.stringify(event.body)}`);\n    }\n    \u002F\u002F Checkpoint after processing batch\n    if (events.length > 0) {\n      await context.updateCheckpoint(events[events.length - 1]);\n    }\n  },\n  processError: async (err, context) => {\n    console.error(`Error: ${err.message}`);\n  },\n});\n```\n\n### Receive from Specific Position\n\n```typescript\nconst subscription = consumer.subscribe({\n  processEvents: async (events, context) => { \u002F* ... *\u002F },\n  processError: async (err, context) => { \u002F* ... *\u002F },\n}, {\n  startPosition: {\n    \u002F\u002F Start from beginning\n    \"0\": { offset: \"@earliest\" },\n    \u002F\u002F Start from end (new events only)\n    \"1\": { offset: \"@latest\" },\n    \u002F\u002F Start from specific offset\n    \"2\": { offset: \"12345\" },\n    \u002F\u002F Start from specific time\n    \"3\": { enqueuedOn: new Date(\"2024-01-01\") },\n  },\n});\n```\n\n## Event Hub Properties\n\n```typescript\n\u002F\u002F Get hub info\nconst hubProperties = await producer.getEventHubProperties();\nconsole.log(`Partitions: ${hubProperties.partitionIds}`);\n\n\u002F\u002F Get partition info\nconst partitionProperties = await producer.getPartitionProperties(\"0\");\nconsole.log(`Last sequence: ${partitionProperties.lastEnqueuedSequenceNumber}`);\n```\n\n## Batch Processing Options\n\n```typescript\nconst subscription = consumer.subscribe(\n  {\n    processEvents: async (events, context) => { \u002F* ... *\u002F },\n    processError: async (err, context) => { \u002F* ... *\u002F },\n  },\n  {\n    maxBatchSize: 100,           \u002F\u002F Max events per batch\n    maxWaitTimeInSeconds: 30,    \u002F\u002F Max wait for batch\n  }\n);\n```\n\n## Key Types\n\n```typescript\nimport {\n  EventHubProducerClient,\n  EventHubConsumerClient,\n  EventData,\n  ReceivedEventData,\n  PartitionContext,\n  Subscription,\n  SubscriptionEventHandlers,\n  CreateBatchOptions,\n  EventPosition,\n} from \"@azure\u002Fevent-hubs\";\n\nimport { BlobCheckpointStore } from \"@azure\u002Feventhubs-checkpointstore-blob\";\n```\n\n## Event Properties\n\n```typescript\n\u002F\u002F Send with properties\nconst batch = await producer.createBatch();\nbatch.tryAdd({\n  body: { data: \"payload\" },\n  properties: {\n    eventType: \"telemetry\",\n    deviceId: \"sensor-1\",\n  },\n  contentType: \"application\u002Fjson\",\n  correlationId: \"request-123\",\n});\n\n\u002F\u002F Access in receiver\nconsumer.subscribe({\n  processEvents: async (events, context) => {\n    for (const event of events) {\n      console.log(`Type: ${event.properties?.eventType}`);\n      console.log(`Sequence: ${event.sequenceNumber}`);\n      console.log(`Enqueued: ${event.enqueuedTimeUtc}`);\n      console.log(`Offset: ${event.offset}`);\n    }\n  },\n});\n```\n\n## Error Handling\n\n```typescript\nconsumer.subscribe({\n  processEvents: async (events, context) => {\n    try {\n      for (const event of events) {\n        await processEvent(event);\n      }\n      await context.updateCheckpoint(events[events.length - 1]);\n    } catch (error) {\n      \u002F\u002F Don't checkpoint on error - events will be reprocessed\n      console.error(\"Processing failed:\", error);\n    }\n  },\n  processError: async (err, context) => {\n    if (err.name === \"MessagingError\") {\n      \u002F\u002F Transient error - SDK will retry\n      console.warn(\"Transient error:\", err.message);\n    } else {\n      \u002F\u002F Fatal error\n      console.error(\"Fatal error:\", err);\n    }\n  },\n});\n```\n\n## Best Practices\n\n1. **Use checkpointing** - Always checkpoint in production for exactly-once processing\n2. **Batch sends** - Use `createBatch()` for efficient sending\n3. **Partition keys** - Use partition keys to ensure ordering for related events\n4. **Consumer groups** - Use separate consumer groups for different processing pipelines\n5. **Handle errors gracefully** - Don't checkpoint on processing failures\n6. **Close clients** - Always close producer\u002Fconsumer when done\n7. **Monitor lag** - Track `lastEnqueuedSequenceNumber` vs processed sequence\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,129,1039,"2026-05-16 13:06:25",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"b3a93936-b610-41d2-85ea-1f5183b1eea7","1.0.0","azure-eventhub-ts.zip",2468,"uploads\u002Fskills\u002Fa9877139-49b1-4a93-89c6-19801a59af8d\u002Fazure-eventhub-ts.zip","ecbad8a8c58bf428b87a61c002a6e516ebdf7fe2e7bd2ed0eed2a66c882e35cd","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":7414}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]