nats-io / nats-kafka

NATS to Kafka Bridging
Apache License 2.0
131 stars 32 forks source link

Add JetStream support #49

Closed variadico closed 3 years ago

variadico commented 3 years ago

This adds JetStream support to nats-kafka. It's based off the NATS and STAN implementations.

Closes #41

Testing

You can run the tests locally like this. (Automatically sets up and tears down Docker containers and runs Go tests.)

make test

In addition, this is how I tested manually.

# Start a Kafka server, available at localhost:9092
make setup-docker-test

# Start NATS Server with JetStream, localhost:4222
nats-server -DVV -js

# Create Stream for baz
nats stream create --subjects baz mystream1

# Create Stream for bang
nats stream create --subjects bang mystream2

# Create Consumer
nats consumer add --target mytarget mystream2 myconsumer2

# Start nats-kafka
nats-kafka -c nats-kafka.conf

# Publish on Stream
nats pub baz "hi $(date)"

# Subscribe on delivery subject
nats sub mytarget

# Shutdown Kafka
make teardown-docker-test

Here's the config file.

nats: {
  Servers: ["localhost:4222"],
}

jetstream: {
    maxwait: 5000,
}

connect: [
  {
      type: "JetStreamToKafka",
      brokers: ["localhost:9092"]
      id: "foo",
      topic: "bar",
      subject: "baz",
  },
  {
    type: "KafkaToJetStream",
    brokers: ["localhost:9092"]
    id: "whizz",
    topic: "bar",
    subject: "bang",
  },
]
variadico commented 3 years ago

I was thinking of doing a follow up PR to include documentation, since his PR is a little big already.

codecov-commenter commented 3 years ago

Codecov Report

Merging #49 (6cbfbef) into main (acd46a8) will decrease coverage by 0.40%. The diff coverage is 72.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #49      +/-   ##
==========================================
- Coverage   75.70%   75.30%   -0.41%     
==========================================
  Files          16       18       +2     
  Lines        1099     1247     +148     
==========================================
+ Hits          832      939     +107     
- Misses        195      215      +20     
- Partials       72       93      +21     
Impacted Files Coverage Δ
server/conf/conf.go 78.94% <ø> (ø)
server/core/server.go 57.36% <50.00%> (-0.50%) :arrow_down:
server/core/kafka2jetstream.go 70.73% <70.73%> (ø)
server/core/connector.go 71.48% <74.00%> (+0.61%) :arrow_up:
server/core/nats.go 58.88% <75.00%> (+3.48%) :arrow_up:
server/core/jetstream2kafka.go 79.31% <79.31%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update acd46a8...6cbfbef. Read the comment docs.

ColinSullivan1 commented 3 years ago

LGTM. Thanks! A future PR could create streams and consumers dynamically, but this is good for the time being.