karatelabs / karate-addons

1 stars 1 forks source link

info: Can kafta addon be used to create imposters #3

Open fjvierap opened 8 months ago

fjvierap commented 8 months ago

I would like to use kafka addon as imposter. Our scenario is that will have an EDA application which will consume a message from a third party will do some logic, produce a message to be consumer by another third party and the process will sleep until the third party application will respond will another message. My idea was to create a feature which consume message and based on conditions will producer other messages:

Feature: karate-kafka demo

Background:
* configure kafka =
"""
{
  'bootstrap.servers': '127.0.0.1:9092',
  'schema.registry.url': 'http://localhost:8082',
  'schema.registry.basic.auth.credentials.source' : 'USER_INFO',
  'schema.registry.basic.auth.user.info' : 'farbod:test_secret'

}
"""

* register { name: 'order-notification', path: 'classpath:karate/order-notification-avro.avsc' }

Scenario:
* def session = karate.consume('kafka')
* session.topic = 'order'
* session.count = 1
* session.start()

* def response = session.collect()
* if (response[0].value == { id: 'id' }) print 'here produce a message'

Then in some other feature call this mock feature.

Feature: karate-kafka demo

Background:
* configure kafka =
"""
{
  'bootstrap.servers': '127.0.0.1:9092',
  'schema.registry.url': 'http://localhost:8082',
  'schema.registry.basic.auth.credentials.source' : 'USER_INFO',
  'schema.registry.basic.auth.user.info' : 'farbod:test_secret'

}
"""

* register { name: 'order-notification', path: 'classpath:karate/order-notification-avro.avsc' }

Scenario:
* karate.callSingle('mock.feature')

* topic 'order'
* schema 'order-notification'
* headers { foo: 'bar1', baz: 'ban1' }
* key 'first'
* value { id: 'someid' }
* produce kafka

But this approach does not work as the threat keep in the mock expecting to consumer message and the main feature got stuck and not progress..

I guess I am not doing it in the best way. What is the proper approach to use kafka addon for this scenatrio?

Thanks in advance

ptrthomas commented 8 months ago

@fjvierap a kafka mock would need a different design - mainly it has to start as a server and "listen" all the time and manage threads better. we have this on the roadmap and I can get back to you on timelines.

fjvierap commented 8 months ago

@ptrthomas it would be very convenient to know the timelines for it and if it would be some alternative for mocking kafka consumers.

Thanks in advance

ptrthomas commented 8 months ago

@fjvierap give me a day or two to confirm, but It can be as soon as by Q1 (March). for alternatives, this may help, but requires some custom Java code: https://twitter.com/getkarate/status/1417023536082812935