SlideShare a Scribd company logo
Classificatie: vertrouwelijk
Conclusion Code
Café Microcks –
testing &
mocking
Async APIs
11-01-2022
Classificatie: vertrouwelijk
The Interface of a Service
API
HTTP REST/JSON
Code Café Microcks - January 2022
µ
HTTP/2 gRPC/ProtoBuf
HTTP SOAP/XML
Kafka
MQTT
WebSocket
HTTP
JMS
AMQP
STOMP
NATS, SNS, SQS,
Redis, RabbitMQ
Kafka
MQTT
WebSocket
HTTP
JMS
AMQP
STOMP
NATS, SNS, SQS,
Redis, RabbitMQ
2
Classificatie: vertrouwelijk
AsyncAPI
• Design Time
• Event Driven Architecture
• Pub/Sub
• Asynchronous Interactions
• API Design
• Interface Definition/Contract
Code Café Microcks - January 2022 3
Classificatie: vertrouwelijk
AsyncAPI
• Compare OpenAPI
• Describes an API (in yaml or json) to consumers
• invitation to publish events on a certain topic
on which the API is subscribed and from which it consumes
• invitation to subscribe to a certain topic (that the API publishes to)
• the message structure that is actually published or consumed
• Used to generate code for publishing or consuming
• and provide documentation for developers and testers
• Used to drive Mock-tools to publish the event said to be consumed
• Used to drive Test-tools-tools to listen for the events claimed to be published
• Sponsored by Solace, Postman, IBM, SalesForce, MuleSoft, IQVia, Tibco,
SAP, Slack
Code Café Microcks - January 2022 4
Classificatie: vertrouwelijk
AsynchAPI Interface Definition
• Define for an API
• the Channel (queue, topic, …) the API subscribes to
• the message type the API expects to consume
• the Channel the API publishes to
• the message type the API publishes
• the Servers on which the API connects
• Kafka Broker, HTTP url endpoint, RabbitMQ Broker endpoint
• link between Channel and Server(s) (channel binding)
• Developer and tools can interpret this definition
• generate code, stubs, mocks, tests
Code Café Microcks - January 2022 5
PUBLISH
SUBSCRIBE
Classificatie: vertrouwelijk
Testing and Mocking Async APIs with Microcks
Code Café Microcks - January 2022 6
load & interpret AsyncAPI definitions
Mock implementation
that publishes events
to channel (just as the
real API would do)
Test that subscribes
and consumes
messages that API
promises to publish
Kafka
MQTT
WebSocket
Kafka
MQTT
WebSocket
Classificatie: vertrouwelijk
application.properties
Running Microcks with Docker Compose
(with async-api enabled)
Code Café Microcks - January 2022 7
Kafka
docker-compose.yml docker-compose-async-addon.yml kafdrop-addon.yml
Kaf
Drop
Mongo
DB
Key
Cloak
microcks-
postman
microcks
async-
minion
Zoo
keeper
UI
UI
UI
features.properties
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 9
Classificatie: vertrouwelijk
Microcks and Async APIs
• Prepare AsyncAPI interface definition
• message definitions, channel name
• examples (used for mocked messages) – including function expressions
such as {{now(yyyy-mm-dd)}}, {{uuid()}}, {{randomFirstName()}}
• Import API contract in Microcks
• Microcks will automatically
• validate interface and exposes API documentation
• start publishing mock messages to default channel binding (i.e. Kafka)
• when other channel bindings are declared, then these too (WS, MQTT)
• Consume mock messages in event client application under development
• …
Code Café Microcks - January 2022 10
Classificatie: vertrouwelijk
WS
MQTT
Application can Consume Correct Messages through Real
Channel published by generated Mock
Code Café Microcks - January 2022 11
load & interpret AsyncAPI definitions
Mock implementation that
publishes events to channel
(just as the real API would do)
Kafka
Kaf
Drop
UI
Application
under Development
subscribe & consume
Event Client can be
generated from Async
API interface definition
Mock
API
implemen-
tation
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 12
Translated by Microcks to topic
CodeCafeAdvancedStreetlightsAPI-1.1-smartylighting-
codecafe-streetlights-event-lighting-measured
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 13
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 14
load &
interpret
AsyncAPI
definitions
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 15
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 16
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 17
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 18
load & interpret AsyncAPI definitions
Kafka
Kaf
Drop
UI
Mock
API
implemen-
tation
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 19
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 20
Kafka Application
under Development
subscribe & consume
Mock
API
implemen-
tation
Classificatie: vertrouwelijk
Microcks and Async APIs
• Prepare AsyncAPI interface definition
• message definitions, channel name
• Import API contract in Microcks
• Microcks automatically
• validates interface and exposes API documentation
• starts publishing mock messages to default channel binding (i.e. Kafka)
• when other channel bindings are declared, then these too (WS, MQTT)
• Consume mock messages in event client application under development
• Create Test in Microcks: validate messages published by application under
test to a specific endpoint
• messages to validate can be consumed from topic on Kafka Broker,
MQTT Broker or WebSocket Server
Code Café Microcks - January 2022 21
Classificatie: vertrouwelijk
Microcks can generate and run tests on the messages
published by producing application
Code Café Microcks - January 2022 22
load & interpret AsyncAPI definitions
Kafka
Application
under Development
MQTT
Web
Socket
Test that subscribes and
consumes messages that
API promises to publish
subscribe
&
consume
Event producing code can
be generated from Async
API interface definition
Classificatie: vertrouwelijk
Validate the example messages produced by Mock
Code Café Microcks - January 2022 23
load & interpret AsyncAPI definitions
Kafka
Test that subscribes and
consumes messages that
API promises to publish
load & interpret AsyncAPI definitions
Mock
API
implemen-
tation
Validate correctness of
Mock-produced events
Classificatie: vertrouwelijk
Validate the example messages produced by Mock
Code Café Microcks - January 2022 24
Classificatie: vertrouwelijk
Validate the example messages produced by Mock
Code Café Microcks - January 2022 25
Change message
schema in
AysyncAPI
Examples do not
comply
Test fails
load &
interpret
AsyncAPI
definitions
Reload AsyncAPI
definition
Classificatie: vertrouwelijk
Validate the example messages produced by Mock
Code Café Microcks - January 2022 26
Test on Mock
generated
messages fails
Classificatie: vertrouwelijk
Conclusion on Microcks & Async APIs
• AsyncAPI is standard for defining API interface for consuming or producing messages
asynchronously
• via queue | event broker | web socket
• Microcks understands AsyncAPI contracts – but only SUBSCRIBE operations
• generates Mock implementation of API that produces messages
• generates Tests that validate events produced against contract
• support for WS, Kafka, MQTT
• No support in Microcks for
• PUBLISH operation (that invites API clients to publish their events)
• No Mock Event Consumers and no Tests on “proper consumption”
• how useful would this be?
• other Async channels (JMS, AMQP, STOMP, NATS, SNS, SQS, Redis, RabbitMQ,…)
• Microcks installs with out of the box integrated Kafka broker and WebSocket server
Code Café Microcks - January 2022 27
Classificatie: vertrouwelijk
Steps
• Create Kafka Topic streetlight-dropbox
• Configure publishTopic in Kafka Binding
entry in Dapr components.yaml
Code Café Microcks - January 2022 28
out
in
app-id(s) to route to
Classificatie: vertrouwelijk
Steps (2)
• Run a Dapr application with the components.yaml
dapr run –components-path .
• Remember the HTTP port at which Dapr is listening
• Publish an event through Dapr
curl -X POST http://localhost:37919/v1.0/bindings/advanced-street-light-
destination 
-H "Content-Type: application/json" 
-d '{"data": {"streetlightId": "dev99",.... } , "operation": "create"}'
Code Café Microcks - January 2022 29
Classificatie: vertrouwelijk
Steps (3)
• Check the event in Kafdrop
• Run test in Microcks UI on endpoint kafka://kafka:19092/streetlight-dropbox
• Publish an(other) event (for the test to consume)
Code Café Microcks - January 2022 30
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 31
Classificatie: vertrouwelijk
To create Kafka consuming application with Dapr
• Create Kafka Binding entry in components.yaml
• name of the binding
• endpoints for one or more Kafka brokers
• topic(s) to subscribe to
• consumergroup name
• the applications to route
incoming messages to
Code Café Microcks - January 2022 32
Classificatie: vertrouwelijk
Create generic application
that can receive POST request (from Dapr side car)
• Incoming messages are posted to application from side car at path equal to /binding-name
in components.yaml (in this case: /advanced-street-light-destination)
Code Café Microcks - January 2022 33
Classificatie: vertrouwelijk
Run Consuming application as Daprized application
dapr run --app-id street-light-consumer --app-port 3000 node app.js -
-components-path .
• Run this command in the directory that contains both app.js and components.yaml
• Make sure that:
• app-port corresponds with the port on which the application listens
• app-id corresponds with the value used in the scopes element in the
components.yaml file
Code Café Microcks - January 2022 34
Classificatie: vertrouwelijk
Code Café Microcks - January 2022 35

More Related Content

What's hot (20)

PPTX
Intro to Azure DevOps
Lorenzo Barbieri
 
PDF
Messaging queue - Kafka
Mayank Bansal
 
PDF
OpenAPI 3.0, And What It Means for the Future of Swagger
SmartBear
 
PPTX
OAuth in the Wild
Victor Rentea
 
PDF
Application modernization patterns with apache kafka, debezium, and kubernete...
Bilgin Ibryam
 
PDF
Apache Kafka Architecture & Fundamentals Explained
confluent
 
PDF
Apigee Demo: API Platform Overview
Apigee | Google Cloud
 
PDF
Rego Deep Dive
Torin Sandall
 
PDF
Expose your event-driven data to the outside world using webhooks powered by ...
HostedbyConfluent
 
PDF
Jenkins-CI
Gong Haibing
 
PDF
OSMC 2022 | The Power of Metrics, Logs & Traces with Open Source by Emil-Andr...
NETWAYS
 
PDF
Distributed tracing using open tracing & jaeger 2
Chandresh Pancholi
 
PDF
Microservices, Kubernetes and Istio - A Great Fit!
Animesh Singh
 
PPTX
Terraform Basics
Mohammed Fazuluddin
 
PPTX
API Security Lifecycle
Apigee | Google Cloud
 
PDF
Hands-On Introduction to Kubernetes at LISA17
Ryan Jarvinen
 
PPTX
RabbitMQ & Kafka
VMware Tanzu
 
PDF
Marcel Hild - Spryker (e)commerce framework als Alternative zu traditioneller...
AboutYouGmbH
 
PPTX
Building a scalable microservice architecture with envoy, kubernetes and istio
SAMIR BEHARA
 
PDF
Kafka Streams: What it is, and how to use it?
confluent
 
Intro to Azure DevOps
Lorenzo Barbieri
 
Messaging queue - Kafka
Mayank Bansal
 
OpenAPI 3.0, And What It Means for the Future of Swagger
SmartBear
 
OAuth in the Wild
Victor Rentea
 
Application modernization patterns with apache kafka, debezium, and kubernete...
Bilgin Ibryam
 
Apache Kafka Architecture & Fundamentals Explained
confluent
 
Apigee Demo: API Platform Overview
Apigee | Google Cloud
 
Rego Deep Dive
Torin Sandall
 
Expose your event-driven data to the outside world using webhooks powered by ...
HostedbyConfluent
 
Jenkins-CI
Gong Haibing
 
OSMC 2022 | The Power of Metrics, Logs & Traces with Open Source by Emil-Andr...
NETWAYS
 
Distributed tracing using open tracing & jaeger 2
Chandresh Pancholi
 
Microservices, Kubernetes and Istio - A Great Fit!
Animesh Singh
 
Terraform Basics
Mohammed Fazuluddin
 
API Security Lifecycle
Apigee | Google Cloud
 
Hands-On Introduction to Kubernetes at LISA17
Ryan Jarvinen
 
RabbitMQ & Kafka
VMware Tanzu
 
Marcel Hild - Spryker (e)commerce framework als Alternative zu traditioneller...
AboutYouGmbH
 
Building a scalable microservice architecture with envoy, kubernetes and istio
SAMIR BEHARA
 
Kafka Streams: What it is, and how to use it?
confluent
 

More from Lucas Jellema (20)

PPTX
Introduction to web application development with Vue (for absolute beginners)...
Lucas Jellema
 
PPTX
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
Lucas Jellema
 
PPTX
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
Lucas Jellema
 
PPTX
Apache Superset - open source data exploration and visualization (Conclusion ...
Lucas Jellema
 
PPTX
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
Lucas Jellema
 
PPTX
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
Lucas Jellema
 
PPTX
Op je vingers tellen... tot 1000!
Lucas Jellema
 
PPTX
IoT - from prototype to enterprise platform (DigitalXchange 2022)
Lucas Jellema
 
PPTX
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Lucas Jellema
 
PPTX
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
Lucas Jellema
 
PPTX
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
Lucas Jellema
 
PPTX
Introducing Dapr.io - the open source personal assistant to microservices and...
Lucas Jellema
 
PPTX
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
Lucas Jellema
 
PPTX
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Lucas Jellema
 
PPTX
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
Lucas Jellema
 
PPTX
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
Lucas Jellema
 
PPTX
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
Lucas Jellema
 
PPTX
Tech Talks 101 - DevOps (jan 2022)
Lucas Jellema
 
PPTX
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Lucas Jellema
 
PPTX
Software Engineering as the Next Level Up from Programming (Oracle Groundbrea...
Lucas Jellema
 
Introduction to web application development with Vue (for absolute beginners)...
Lucas Jellema
 
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
Lucas Jellema
 
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
Lucas Jellema
 
Apache Superset - open source data exploration and visualization (Conclusion ...
Lucas Jellema
 
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
Lucas Jellema
 
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
Lucas Jellema
 
Op je vingers tellen... tot 1000!
Lucas Jellema
 
IoT - from prototype to enterprise platform (DigitalXchange 2022)
Lucas Jellema
 
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Lucas Jellema
 
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
Lucas Jellema
 
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
Lucas Jellema
 
Introducing Dapr.io - the open source personal assistant to microservices and...
Lucas Jellema
 
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
Lucas Jellema
 
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Lucas Jellema
 
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
Lucas Jellema
 
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
Lucas Jellema
 
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
Lucas Jellema
 
Tech Talks 101 - DevOps (jan 2022)
Lucas Jellema
 
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Lucas Jellema
 
Software Engineering as the Next Level Up from Programming (Oracle Groundbrea...
Lucas Jellema
 
Ad

Recently uploaded (20)

PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
PDF
interacting-with-ai-2023---module-2---session-3---handout.pdf
cniclsh1
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
interacting-with-ai-2023---module-2---session-3---handout.pdf
cniclsh1
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Ad

Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2022)

  • 1. Classificatie: vertrouwelijk Conclusion Code Café Microcks – testing & mocking Async APIs 11-01-2022
  • 2. Classificatie: vertrouwelijk The Interface of a Service API HTTP REST/JSON Code Café Microcks - January 2022 µ HTTP/2 gRPC/ProtoBuf HTTP SOAP/XML Kafka MQTT WebSocket HTTP JMS AMQP STOMP NATS, SNS, SQS, Redis, RabbitMQ Kafka MQTT WebSocket HTTP JMS AMQP STOMP NATS, SNS, SQS, Redis, RabbitMQ 2
  • 3. Classificatie: vertrouwelijk AsyncAPI • Design Time • Event Driven Architecture • Pub/Sub • Asynchronous Interactions • API Design • Interface Definition/Contract Code Café Microcks - January 2022 3
  • 4. Classificatie: vertrouwelijk AsyncAPI • Compare OpenAPI • Describes an API (in yaml or json) to consumers • invitation to publish events on a certain topic on which the API is subscribed and from which it consumes • invitation to subscribe to a certain topic (that the API publishes to) • the message structure that is actually published or consumed • Used to generate code for publishing or consuming • and provide documentation for developers and testers • Used to drive Mock-tools to publish the event said to be consumed • Used to drive Test-tools-tools to listen for the events claimed to be published • Sponsored by Solace, Postman, IBM, SalesForce, MuleSoft, IQVia, Tibco, SAP, Slack Code Café Microcks - January 2022 4
  • 5. Classificatie: vertrouwelijk AsynchAPI Interface Definition • Define for an API • the Channel (queue, topic, …) the API subscribes to • the message type the API expects to consume • the Channel the API publishes to • the message type the API publishes • the Servers on which the API connects • Kafka Broker, HTTP url endpoint, RabbitMQ Broker endpoint • link between Channel and Server(s) (channel binding) • Developer and tools can interpret this definition • generate code, stubs, mocks, tests Code Café Microcks - January 2022 5 PUBLISH SUBSCRIBE
  • 6. Classificatie: vertrouwelijk Testing and Mocking Async APIs with Microcks Code Café Microcks - January 2022 6 load & interpret AsyncAPI definitions Mock implementation that publishes events to channel (just as the real API would do) Test that subscribes and consumes messages that API promises to publish Kafka MQTT WebSocket Kafka MQTT WebSocket
  • 7. Classificatie: vertrouwelijk application.properties Running Microcks with Docker Compose (with async-api enabled) Code Café Microcks - January 2022 7 Kafka docker-compose.yml docker-compose-async-addon.yml kafdrop-addon.yml Kaf Drop Mongo DB Key Cloak microcks- postman microcks async- minion Zoo keeper UI UI UI features.properties
  • 8. Classificatie: vertrouwelijk Code Café Microcks - January 2022 9
  • 9. Classificatie: vertrouwelijk Microcks and Async APIs • Prepare AsyncAPI interface definition • message definitions, channel name • examples (used for mocked messages) – including function expressions such as {{now(yyyy-mm-dd)}}, {{uuid()}}, {{randomFirstName()}} • Import API contract in Microcks • Microcks will automatically • validate interface and exposes API documentation • start publishing mock messages to default channel binding (i.e. Kafka) • when other channel bindings are declared, then these too (WS, MQTT) • Consume mock messages in event client application under development • … Code Café Microcks - January 2022 10
  • 10. Classificatie: vertrouwelijk WS MQTT Application can Consume Correct Messages through Real Channel published by generated Mock Code Café Microcks - January 2022 11 load & interpret AsyncAPI definitions Mock implementation that publishes events to channel (just as the real API would do) Kafka Kaf Drop UI Application under Development subscribe & consume Event Client can be generated from Async API interface definition Mock API implemen- tation
  • 11. Classificatie: vertrouwelijk Code Café Microcks - January 2022 12 Translated by Microcks to topic CodeCafeAdvancedStreetlightsAPI-1.1-smartylighting- codecafe-streetlights-event-lighting-measured
  • 12. Classificatie: vertrouwelijk Code Café Microcks - January 2022 13
  • 13. Classificatie: vertrouwelijk Code Café Microcks - January 2022 14 load & interpret AsyncAPI definitions
  • 14. Classificatie: vertrouwelijk Code Café Microcks - January 2022 15
  • 15. Classificatie: vertrouwelijk Code Café Microcks - January 2022 16
  • 16. Classificatie: vertrouwelijk Code Café Microcks - January 2022 17
  • 17. Classificatie: vertrouwelijk Code Café Microcks - January 2022 18 load & interpret AsyncAPI definitions Kafka Kaf Drop UI Mock API implemen- tation
  • 18. Classificatie: vertrouwelijk Code Café Microcks - January 2022 19
  • 19. Classificatie: vertrouwelijk Code Café Microcks - January 2022 20 Kafka Application under Development subscribe & consume Mock API implemen- tation
  • 20. Classificatie: vertrouwelijk Microcks and Async APIs • Prepare AsyncAPI interface definition • message definitions, channel name • Import API contract in Microcks • Microcks automatically • validates interface and exposes API documentation • starts publishing mock messages to default channel binding (i.e. Kafka) • when other channel bindings are declared, then these too (WS, MQTT) • Consume mock messages in event client application under development • Create Test in Microcks: validate messages published by application under test to a specific endpoint • messages to validate can be consumed from topic on Kafka Broker, MQTT Broker or WebSocket Server Code Café Microcks - January 2022 21
  • 21. Classificatie: vertrouwelijk Microcks can generate and run tests on the messages published by producing application Code Café Microcks - January 2022 22 load & interpret AsyncAPI definitions Kafka Application under Development MQTT Web Socket Test that subscribes and consumes messages that API promises to publish subscribe & consume Event producing code can be generated from Async API interface definition
  • 22. Classificatie: vertrouwelijk Validate the example messages produced by Mock Code Café Microcks - January 2022 23 load & interpret AsyncAPI definitions Kafka Test that subscribes and consumes messages that API promises to publish load & interpret AsyncAPI definitions Mock API implemen- tation Validate correctness of Mock-produced events
  • 23. Classificatie: vertrouwelijk Validate the example messages produced by Mock Code Café Microcks - January 2022 24
  • 24. Classificatie: vertrouwelijk Validate the example messages produced by Mock Code Café Microcks - January 2022 25 Change message schema in AysyncAPI Examples do not comply Test fails load & interpret AsyncAPI definitions Reload AsyncAPI definition
  • 25. Classificatie: vertrouwelijk Validate the example messages produced by Mock Code Café Microcks - January 2022 26 Test on Mock generated messages fails
  • 26. Classificatie: vertrouwelijk Conclusion on Microcks & Async APIs • AsyncAPI is standard for defining API interface for consuming or producing messages asynchronously • via queue | event broker | web socket • Microcks understands AsyncAPI contracts – but only SUBSCRIBE operations • generates Mock implementation of API that produces messages • generates Tests that validate events produced against contract • support for WS, Kafka, MQTT • No support in Microcks for • PUBLISH operation (that invites API clients to publish their events) • No Mock Event Consumers and no Tests on “proper consumption” • how useful would this be? • other Async channels (JMS, AMQP, STOMP, NATS, SNS, SQS, Redis, RabbitMQ,…) • Microcks installs with out of the box integrated Kafka broker and WebSocket server Code Café Microcks - January 2022 27
  • 27. Classificatie: vertrouwelijk Steps • Create Kafka Topic streetlight-dropbox • Configure publishTopic in Kafka Binding entry in Dapr components.yaml Code Café Microcks - January 2022 28 out in app-id(s) to route to
  • 28. Classificatie: vertrouwelijk Steps (2) • Run a Dapr application with the components.yaml dapr run –components-path . • Remember the HTTP port at which Dapr is listening • Publish an event through Dapr curl -X POST http://localhost:37919/v1.0/bindings/advanced-street-light- destination -H "Content-Type: application/json" -d '{"data": {"streetlightId": "dev99",.... } , "operation": "create"}' Code Café Microcks - January 2022 29
  • 29. Classificatie: vertrouwelijk Steps (3) • Check the event in Kafdrop • Run test in Microcks UI on endpoint kafka://kafka:19092/streetlight-dropbox • Publish an(other) event (for the test to consume) Code Café Microcks - January 2022 30
  • 30. Classificatie: vertrouwelijk Code Café Microcks - January 2022 31
  • 31. Classificatie: vertrouwelijk To create Kafka consuming application with Dapr • Create Kafka Binding entry in components.yaml • name of the binding • endpoints for one or more Kafka brokers • topic(s) to subscribe to • consumergroup name • the applications to route incoming messages to Code Café Microcks - January 2022 32
  • 32. Classificatie: vertrouwelijk Create generic application that can receive POST request (from Dapr side car) • Incoming messages are posted to application from side car at path equal to /binding-name in components.yaml (in this case: /advanced-street-light-destination) Code Café Microcks - January 2022 33
  • 33. Classificatie: vertrouwelijk Run Consuming application as Daprized application dapr run --app-id street-light-consumer --app-port 3000 node app.js - -components-path . • Run this command in the directory that contains both app.js and components.yaml • Make sure that: • app-port corresponds with the port on which the application listens • app-id corresponds with the value used in the scopes element in the components.yaml file Code Café Microcks - January 2022 34
  • 34. Classificatie: vertrouwelijk Code Café Microcks - January 2022 35

Editor's Notes

  • #2: https://forms.office.com/r/QXtaHEtAAH
  • #11: https://microcks.io/documentation/using/advanced/templates/#function-expressions
  • #23: https://microcks.io/blog/apache-kafka-mocking-testing/
  • #24: https://microcks.io/blog/apache-kafka-mocking-testing/
  • #34: // start application using: // dapr run --app-id street-light-consumer --app-port 3000 node app.js --components-path . const express = require('express'); const bodyParser = require('body-parser'); require('isomorphic-fetch'); const app = express(); app.use(bodyParser.json()); const port = 3000; app.post('/advanced-street-light-destination', (req, res) => {     console.log("Message received from Kafka");     console.log(req.headers);     console.log(req.body);     res.status(200).send(); }); app.listen(port, () => console.log(`Node App listening on port ${port}!`));