Schema-oriented message destination

Schema-oriented message destination

AUTHOR
======

Ricky Ho (rickyphyllis@hotmail.com)
08/28/2001


CONTEXT
=======

When a message producer send a message to a destination (queue or topic), he wants to make sure that he is sending messages to a destination where the consumers can understand. Similarly, when a message consumer receive a message from a destination, he wants to make sure that he can understand all messages he take from the destination.

PROBLEMS
========

In JMS, the producer and consumer are tightly coupled with the message structure. However, there is no relationship between the destination and the message structure. Therefore, the consumer application and producer application needs to agree upfront (at design time) what message structure will be produced or consumed.

(Problem 1):
There is NO standard way for a new producer app or consumer app to learn what message structure they should be used for a destination. They will try to look for existing design documents to find if they mention anything about the message structure. Nevertheless, the only reliable way is to look at source code from existing producer and consumer app. This process is error-prone.

(Problem 2):
If the consumer consumes a message from a queue with an unexpected structure. At best, it detects the message is not understandable and drops it, in this case the message is lost. At worst, the message with wrong structure will crash the consumer app. Well-written consumer applications will take the burden to code the message structure validation logic, resulting in undesirable complexity. Ideally, the message structure should have been verified before passing to the consumer application.

(Problem 3):
Whenever a change is needed for a message structure (usually initiated from one of the message producer), nightmare start. First, we need to trace all the destination where the new message (with the changed message structure) will go to. Second, for each of the destination, we need to trace all the consumer applications and make sure that they are changed apropriately to deal with the new message structure. This tracing can be very difficult when the consumer application dynamically subscribing and receiving from destinations. If we miss the upgrade for one consuming app, we are introducing problem 2.


SOLUTION
========

A destination should only accept one type of message with a particular message structure. The metadata associated with each destination should include the definition of this ONE message structure that it accepts.

Whenever a message is sent to a destination, the JMS container should verifies the message with the specified structure.

Whenever a change is made to a message structure, a new version of destination (by destination naming convention)is created, at the same time all existing consumer applications will received a callback method "onSchemaChange()". Now this new destination will only accept message with the new (changed) message structure. Old producer app without aware of the message structure change can keep sending message with old structure to the old destination which will be consumed by old consumer apps. Because, existing consumer apps will never receive the new message type until they explicitly change to the new destination, they won't break. This mechanism requires the producer and consumer applications to explicitly move to a new destination and accomodate the message structure changes at the same time.


CONSEQUENCE
===========

By enforcing the association between a destination with a message type. We can standardize the mechanism how the producer app and consumer app discover the correct message schema.

By introducing metadata of the destination, a producer app and consumer app can examine that at run time, and hence reducing design-time assumptions.

The destination versioning helps to prevent incompatibilities problems when schema changes.

阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
JSON Schema to TypeScript 是一个将 JSON Schema 转换为 TypeScript 类型定义的工具。JSON Schema 是一种用于描述 JSON 数据结构的语言,它定义了数据的类型、格式以及数据之间的关系。而 TypeScript 是一种静态类型的脚本语言,它为 JavaScript 提供了静态类型检查和支持,增加了代码的可读性和可维护性。 使用 JSON Schema to TypeScript 工具,我们可以将 JSON Schema 文件转换为 TypeScript 类型定义文件,以便在编写 TypeScript 代码时能够方便地使用这些类型定义。这样做的好处是,我们可以在编写代码时利用类型检查来减少错误并提高代码的质量。 例如,假设我们有一个 JSON Schema 文件描述了一个用户对象的结构,包括用户名、年龄和地址。我们可以使用 JSON Schema to TypeScript 工具将这个 JSON Schema 转换为一个 TypeScript 类型定义文件,其中包含了对应的 TypeScript 接口或类型: ```typescript interface User { username: string; age: number; address: string; } ``` 这样,我们就可以在 TypeScript 代码中使用这个 User 类型定义,例如: ```typescript const user: User = { username: "John", age: 20, address: "123 Main St", }; console.log(user.username); // 输出 "John" console.log(user.age); // 输出 20 console.log(user.address); // 输出 "123 Main St" ``` 通过将 JSON Schema 转换为 TypeScript 类型定义,我们可以确保在编写 TypeScript 代码时使用正确的数据类型,并减少因类型错误而引发的bug。JSON Schema to TypeScript 工具为我们提供了更好的类型安全性和代码可靠性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xxcc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值