使用 Entity-Framework Core/RabbitMQ 和 HTTP API 在多个 SQL 数据库之间进行通信的好方法

Good way of communicating between multiple SQL databases using Entity-Framework Core/RabbitMQ and HTTP API's

我已经创建了一个 ASP.Net core 2.0 API 应用程序,这样当一个 put 请求进来时,它会将请求添加到一个 Que (rabbitMQ) 中,然后在请求时将它写入数据库已收到,在我的解决方案下,可以在多个项目中收到此请求,以使用 entity framework.

写入不同的数据库

但是考虑一下,如果我想使用这种方法将数据从一个数据库发送到另一个数据库,我的 SQL 服务器实际上如何使用 json 数据调用这些 API 方法被添加到另一个数据库。

这个想法是完全错误的吗? 是否应该以其他方式完成?

i want to send data from 1 database to another using this method how does my SQL server actually call these API methods with the json data wanted to be added to another database.

最简单的模式是向每个数据库添加一个简单的 table 以用作具有 JSON message_body 列的 "outgoing queue" 以及您想要的任何消息元数据.然后让应用程序服务轮询并对这些 table 执行 "destructive read",将数据转发到适当的队列。

例如

create table outgoing_queue(id bigint identity primary key, message_type varchar(200), message_body nvarchar(max))
go


declare @msg nvarchar(max) = (select * from sys.objects for json auto)

insert into outgoing_queue(message_type,message_body)
values ('message type a', @msg)

go 10 ;


--from the app tier
with q as
(
  select top 1 *
  from outgoing_queue 
  order by id 
)
delete from q
output deleted.*