Must Have on Message Payload

Aug 6, 2023

Having some strict rules on the must, must not, should and should not will allow each domain to define messages that are consistent in metadata and structure and guarantees that the same metadata is present on each message that’s published inside that domain.

In the context of this article, we will define and use:

  • Publisher - the service, application, software component that’s publishing a message.
  • Consumer - a service, application, software component that’s consuming a message.
  • Message - a letter being sent via a messaging mechanism from a publisher to at least one consumer. We will not distinguish between notification, command and message as both notification and command are considered to be a message in this context.

Must Have

Version

Message version should be defined using semantic versioning. Given a version number MAJOR.MINOR.PATCH, increment the:

  • MAJOR version when you make incompatible API changes
  • MINOR version when you add functionality in a backward compatible manner
  • PATCH version when you make backward compatible bug fixes

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

Eg. 1.0.0.

Schema

Location where to find the schema used to define and validate each message from our domain. Location must point to the repository where we keep all our schemas for all messages in our domain. Location should be an absolute path. File names with extension are also acceptable.

Data

This field is the “bag” holding business data that’s shared by this message and that’s of interest for consumers of this message. A message must not be sent if this field is empty or null.

Id

A unique identifier for each message that’s published. It must be a random generated UUID v.4.

Correlation Id

A unique identifier that allows messages bellonging to the same business process to be grouped together. Eg. order-placed.

Source

The publisher of this message. It must be the service, application or what other publisher this message might have. Eg. order-confirmation-service.

Type

The message type identified by namespace. It must be a full namespace. Eg. com.georgeracu.messages.order.confirmation.OrderPlaced.

Created At

The Date Time when this message was created. It must be in UTC, with nanosecond precision. It must be populated when the message is initially created. If immutability is used, the initial value should be carried accross all copies of the initial object.

Published At

The Date Time when this message was published. It must be in UTC, with nanosecond precision. It must be populated before the message is published by the publisher.

Example Schema

Example Payload

{
    "id": "5856bc07-735b-410a-baa4-b96d70745fd9",
    "version": "1.1.0",
    "schema": "",
    "correlationId": "order-placed",
    "source": "order-confirmation-service",
    "type": "com.georgeracu.messages.order.confirmation.OrderPlaced",
    "createdAt": "",
    "publishedAt": "",
    "data": {
        "customerId": "5856bc07-735b-410a-baa4-b96d70745fd9",
        "orderId": "5856bc07-735b-410a-baa4-b96d70745fd9"
    }
}

Tags: programmingmessageasyncapi

Archives

  1. January 2025
  2. The Cost of Slow Pipelines - A Tale of Wasted Time
  3. December 2024
  4. Keeping Software Simple to speed up Software Development
  5. October 2024
  6. The Kanban Café - A Story of Flow
  7. A Story on Accidental Complexity in Software Development
  8. February 2024
  9. Maximizing Software Development Productivity: The Power of Flow and Minimizing Interruptions
  10. December 2023
  11. Clean Code in Java: Writing Code that Speaks
  12. Clean Code in Java: A concise guide
  13. Understanding Value Objects in Java: A Brief Guide
  14. August 2023
  15. Must Have on Message Payload
  16. Centralised Management System For Message Schemas
  17. Consuming RabbitMQ Messages with Clojure: A Step-by-Step Tutorial with Tests
  18. January 2023
  19. Running a Spring Boot service with kubernetes
  20. December 2022
  21. Hosting a PWA with Jekyll and Github pages
  22. November 2022
  23. Global Day of Code Retreat
  24. Facilitating a mini Code Retreat
  25. October 2022
  26. The Curse of Optional
  27. September 2022
  28. Testing Spring Boot Microservices - Presentation
  29. March 2022
  30. TDD Workshop
  31. February 2022
  32. Value Objects in Java
  33. Efficient Java
  34. January 2022
  35. Spring Boot testing - Focus on your changes
  36. Product users - Personas
  37. December 2021
  38. Write code fit for testing
  39. November 2020
  40. Running a Spring Boot app with kubernetes
  41. September 2019
  42. Setup GPG on Mac and sign git repositories
  43. July 2019
  44. Running a Clojure Pedestal application on Raspberry Pi model B revision 2
  45. Clojure from zero to hero (part 3) - First endpoint
  46. Clojure from zero to hero (part 2) - A bit of syntax
  47. June 2019
  48. Clojure from zero to hero (1) - explaining project.clj
  49. Clojure from zero to hero (0) - creating a Pedestal app
  50. November 2017
  51. Introduction to Docker
  52. April 2015
  53. Git micro commits
  54. July 2014
  55. Google Glass Development - setup tools, environment and turn on debugging on Glass
  56. June 2013
  57. How To: Get the rendered HTML of a webpage with Python
  58. Set union of two lists in Python