@ovotech/castle
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -24,2 +24,3 @@ "use strict"; | ||
const services = [producer, ...consumers.map(consumer => consumer.instance)]; | ||
let running = false; | ||
const run = async () => { | ||
@@ -35,10 +36,13 @@ await Promise.all(consumers.map(async ({ instance, config }) => { | ||
producer, | ||
isRunning: () => running, | ||
start: async () => { | ||
await Promise.all(services.map(service => service.connect())); | ||
await run(); | ||
running = true; | ||
}, | ||
stop: async () => { | ||
await Promise.all(services.map(service => service.disconnect())); | ||
running = false; | ||
}, | ||
}; | ||
}; |
export { createCastle, produce, consumeEachMessage, consumeEachBatch } from './castle'; | ||
export { CastleEachMessagePayload, CastleEachBatchPayload, Resolver, Middleware, CastleConsumerConfig, CastleConsumer, CastleConfig, Castle, } from './types'; | ||
export { describeCastle } from './describe'; |
@@ -8,1 +8,3 @@ "use strict"; | ||
exports.consumeEachBatch = castle_1.consumeEachBatch; | ||
var describe_1 = require("./describe"); | ||
exports.describeCastle = describe_1.describeCastle; |
@@ -38,2 +38,3 @@ import { AvroProducer, AvroEachMessagePayload, AvroEachBatchPayload, SchemaRegistryConfig, AvroConsumer, AvroMessage, AvroKafka, TopicsAlias } from '@ovotech/avro-kafkajs'; | ||
producer: AvroProducer; | ||
isRunning: () => boolean; | ||
start: () => Promise<void>; | ||
@@ -40,0 +41,0 @@ stop: () => Promise<void>; |
{ | ||
"name": "@ovotech/castle", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"main": "dist/index.js", | ||
@@ -44,3 +44,3 @@ "types": "dist/index.d.ts", | ||
}, | ||
"gitHead": "9a39f65b885af3195e2ef24f609e971ee4b0e9f5" | ||
"gitHead": "d5505b61f6f196114e94995fb2c519c5b186a1f0" | ||
} |
@@ -14,3 +14,3 @@ # Castle | ||
```typescript | ||
import { createCastle, produce, consumeEachMessage } from '@ovotech/castle'; | ||
import { createCastle, produce, consumeEachMessage, describeCastle } from '@ovotech/castle'; | ||
import { Event, EventSchema } from './avro'; | ||
@@ -38,2 +38,4 @@ | ||
console.log(describeCastle(castle)); | ||
await mySender(castle.producer, [{ value: { field1: 'my-string' } }]); | ||
@@ -52,4 +54,10 @@ }; | ||
```typescript | ||
import { createCastle, produce, consumeEachMessage, consumeEachBatch } from '@ovotech/castle'; | ||
import { | ||
createCastle, | ||
produce, | ||
consumeEachMessage, | ||
consumeEachBatch, | ||
describeCastle, | ||
} from '@ovotech/castle'; | ||
import { | ||
StartEvent, | ||
@@ -63,6 +71,12 @@ StartEventSchema, | ||
enum Topic { | ||
Start = 'start', | ||
Complete = 'complete', | ||
Feedback = 'feedback', | ||
} | ||
// Define multiple producers as pure functions | ||
const sendStart = produce<StartEvent>({ topic: 'start-1', schema: StartEventSchema }); | ||
const sendComplete = produce<CompleteEvent>({ topic: 'complete-1', schema: CompleteEventSchema }); | ||
const sendFeedback = produce<FeedbackEvent>({ topic: 'feedback-1', schema: FeedbackEventSchema }); | ||
const sendStart = produce<StartEvent>({ topic: Topic.Start, schema: StartEventSchema }); | ||
const sendComplete = produce<CompleteEvent>({ topic: Topic.Complete, schema: CompleteEventSchema }); | ||
const sendFeedback = produce<FeedbackEvent>({ topic: Topic.Feedback, schema: FeedbackEventSchema }); | ||
@@ -88,2 +102,10 @@ // Define a consumer as a pure function | ||
const castle = createCastle({ | ||
// Setup topic aliases | ||
// You can use short statically checked names in the code, | ||
// but configure long environment specific kafka topic names | ||
topicsAlias: { | ||
[Topic.Start]: 'start-topic-name-1', | ||
[Topic.Feedback]: 'feedback-topic-name-1', | ||
[Topic.Complete]: 'complete-topic-name-1', | ||
}, | ||
schemaRegistry: { uri: 'http://localhost:8081' }, | ||
@@ -93,3 +115,3 @@ kafka: { brokers: ['localhost:29092'] }, | ||
{ | ||
topic: 'start-1', | ||
topic: Topic.Start, | ||
groupId: 'start-group-1', | ||
@@ -99,3 +121,3 @@ eachMessage: eachStartEvent, | ||
{ | ||
topic: 'feedback-1', | ||
topic: Topic.Feedback, | ||
groupId: 'feedback-group-1', | ||
@@ -105,3 +127,3 @@ eachBatch: eachBatchFeedbackEvent, | ||
{ | ||
topic: 'complete-1', | ||
topic: Topic.Complete, | ||
groupId: 'complete-group-1', | ||
@@ -116,2 +138,4 @@ partitionsConsumedConcurrently: 2, | ||
console.log(describeCastle(castle)); | ||
// Perform a siqeunce of events | ||
@@ -141,3 +165,3 @@ // - send start events, wait a bit | ||
```typescript | ||
import { createCastle, produce, consumeEachMessage } from '@ovotech/castle'; | ||
import { createCastle, describeCastle, produce, consumeEachMessage } from '@ovotech/castle'; | ||
import { StartEvent, StartEventSchema, CompleteEvent, CompleteEventSchema } from './avro'; | ||
@@ -199,2 +223,4 @@ import { | ||
console.log(describeCastle(castle)); | ||
await start(castle.producer, [{ value: { id: 1 } }]); | ||
@@ -201,0 +227,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17060
11
152
250