We are planning to rewrite our backend of a bigger application.
我们正计划重写一个更大的应用程序的后端。
One part of it is to use some kind of message bus or message queue system.
它的一部分是使用某种类型的消息总线或消息队列系统。
We are looking for a framework where the following code would work.
我们正在寻找一个框架,以下代码将工作。
var topic = "products";
var mq = MessageQueueFactory.CreateMessageQueue(topic);
ProductInformation result = await mq.Publish(new ProductInformationSearchRequest(1337));
// work with the result
Something like that.
I know it's kind of against the idea of the system to wait for the response in the same function where the request was issued.
差不多是这样。我知道在发出请求的同一函数中等待响应有点违背系统的想法。
There are some frameworks, that can answer to a session. But you would have a seperate Response-Queue.
有一些框架可以回答会话的问题。但你会有一个独立的响应队列。
Our goal is to send some information into a queue. The frameworks finds a destination to send the message to and after the destination responded i get my result back. Multiple destination (of the same kind) might exist. Not all requests need to be answered. Only thoose that are flaged to do so. A Message Broker or similar would be fine as well.
我们的目标是将一些信息发送到队列中。框架会找到一个目的地来发送消息,并且在目的地响应之后,我会得到我的结果。可能存在多个(相同类型的)目的地。并不是所有请求都需要得到答复。只有被标记为这样做的THooSE。消息代理或类似的应用程序也很好。
Is there something that exists, or do i have to build a wrapper around something? With this kind of architecture we can eliminate dependencies that some microservice have right now.
Or do we even have to change our architecure for a system like this to work? Does this even makes sense?
有没有什么东西是存在的,或者我必须围绕着什么东西建立一个包装器?使用这种架构,我们可以消除一些微服务目前存在的依赖。或者,我们甚至必须更改我们的体系结构才能使这样的系统工作吗?这有意义吗?
Btw.: the old way was/is to use REST and an API-Gateway to communicate between the services.
顺便说一句:过去/现在的老方法是使用REST和API-Gateway在服务之间进行通信。
更多回答
Waiting for the result sounds wrong to me. Because the idea of a message system is to decouple things und do async work. So when you send a message and wait for the result you're synching things together again. So insted of waiting I think you have to fire a message. Someone listen for this message and do some work. When he's finished he could send a new message which someone else listen for and do some work and so on. We're using AzureServiceBus this between different applications/services. But I'm not a message queue / architect expert.
对我来说,等待结果听起来不太对劲。因为消息系统的想法是将事物分离,并进行异步工作。因此,当你发送一条消息并等待结果时,你是在再次同步所有东西。这么长时间的等待,我想你必须发出一条信息。谁来听听这条信息,然后做些工作。当他完成后,他可以发送一条新的消息,让其他人监听,并做一些工作,等等。我们在不同的应用程序/服务之间使用AzureServiceBus。但我不是消息队列/架构师专家。
I'm neither. But to do exactly what you described is my backup plan.
我都不是。但完全按照你所说的去做是我的后备计划。
I'd ask first, why are you considering going away from REST and API gateway? Your model above looks a lot like [gRPC][1] - have you considered that? [1]: grpc.io
我首先会问,你为什么要考虑放弃REST和API网关?你上面的模型看起来很像[GRPC][1]-你考虑过吗?[1]:grpc.io
Look at the temporal.io. It allows writing code that looks like a synchronous invocation, but internally is fully asynchronous, uses queues and preserves state of the invocation as long as necessary.
看看这个临时的.io。它允许编写看起来像同步调用的代码,但在内部是完全异步的,使用队列并在必要时保留调用状态。
更多回答
我是一名优秀的程序员,十分优秀!