MQ与Webservice的区别

2023-05-16

Webservice 和MQ(MessageQueue)都是解决跨平台通信的常用手段,两者有哪些区别呢?


个人认为最本质的区别在于 Webservice近乎实时通信,而MQ却通常是延时通信。
什么意思呢?
因为webservice其实就是本地服务器程序调用远程服务器上的方法,属于两者之间的交互,请求的时候需要等被请求的服务器做出回应后,另一端才会有所动作,也就是说,如果你请求的service服务器关闭了,或者中断了,那么你这边肯定就得不到答复了,你的这次请求就算是打水漂丢失了。
 
而MQ 则相当于是多了一个中间件
我所发送的请求 都必须先传达给 这个消息队列组件,然后由这个消息队列组件再去到另一个服务器上去请求,有了响应之后再 返回给
当初的请求程序,因为MessageQueue组件会把消息持久化放在本地,所以哪怕突然死机了,请求消息也是不会丢失的。
Message Queue属于比较重量级的应用, 在规范化的企业流程中用的比较多 。如果企业有很多部门,部门都有自己的系统,那么不同的系统之间的集成通信,Message Queue是很好的选择。 MQ一般都做为企业级IT应用的中间件存在,有很多企业是作为标准IT基础结构存在的。 在市面上常见的MQ中间件有IBM websphere message queue service,Oracle Advanced Queuing,Microsoft Message Queue(MSMQ),Apache ActiveMQ等

如果使用WebService的话,就要写很多的WebService的代码,去建立这些WebServcie,然后暴露出这些接口,相互之间调用,很费事。但是如果使用Message Queue的话,只要把这个中间件的服务器搭建起来,只要在需要的时候加入不同的Queue Manager就可以了,然后就可以访问了,就可以作为不同系统之间的桥梁了。

长耗时的报表,这个在程序中经常遇见,处理海量数据时,可能生成一个报表需要5分中或是更长的时间,客户不能在线实时等待,报表处理比较耗费资源,不能同时处理很多请求,甚至同时只允许处理一个,这时就可以使用MQ。客户端将报表请求和一些必要的报表条件放到Queue中,报表由另一个服务一个一个的处理,处理好后再给用户发一个消息(MSN消息,或mail等)用户再在浏览器或其他报表浏览器中查看报表。

在线商店,在客户下订单的过程后,系统只需做减库存、记录收货人信息和必要的日志,其他的必须配送处理、交易统计等其他处理可以不同时完成,这时就可以将后续处理消息放入Queue中,让另一台(组)服务器去处理,这样可以加快下订单的过程,提高客户的体验;

WebService通常是实时性要求较高,Client端向Server端发出请求后,这是一个短连接,一个Http请求,这个请求发出后,Client端就会一直等到获取到这个结果。但是使用MQ的话,因为有了中间的这一块区域,当请求发出后,Client端可以继续去干别的事情。等到一段时间以后再去中间件的存储区域上查看一下有结果了么,有了结果就取出来,没有的话就再等会再看。
常见的MQ组件 包括MSMQ ,Apache ActiveMQ以及一些开源mq等。
 
贴上一个例子:

In this article, I will introduce a new and independent Open Source Message Queue system that is entirely built in C# and .NET framework 3.5. DotNetMQ is a message broker that has several features including guaranteed delivering, routing, load balancing, server graphs... so on. I will start by explaining messaging concepts and the need for message brokers. Then I will examine what DotNetMQ is and how to use it.

What Is Messaging?

Messaging is a way of asynchronous communication of applications running on same or different machines with reliable delivery. Programs communicate by sending packets of data called messages to each other [1].

A message may be a string, a byte array, an object... etc. Typically, a sender (producer) program creates a message and pushes it to a message queue and a receiver (consumer) program gets the message from the queue and processes it. The sender and receiver programs don’t have to be running at the same time, since messaging is an asynchronous process. This is called loosely coupled communication.

On the other hand, a Web Service method call (Remote Method Invocation) is a type of tightly coupled andsynchronous communication (both applications have to be running and available during the whole communication; if the Web Service is offline or an error occurs during the method call, the client application gets an exception).

 

In the figure above, two applications communicate over a message queue in a loosely coupled manner. If the receiver consumes messages slower than the sender produces it, the message count on the queue will increase. Also, the receiver may be offline while the sender is sending messages. In this situation, the receiver gets the messages from the queue when it becomes online (when it starts and joins the queue).

Message Queues are typically provided by Message Brokers. A Message Broker is a standalone application (service) that other applications connect to and send/receive messages. A Message Broker is responsible to store messages until a receiver receives them. A Message Broker can route messages across machines to deliver a message to the destination application and can try delivering the message until the receiver correctly handles it. A Message Broker is sometimes called a Message Oriented Middleware (MOM) or simply Message Queue (MQ).

DotNetMQ is an open source Message Broker that has several features:

  • Persistent or non-persistent messaging.
  • Guaranteed delivery of persistent messages even in a system crash.
  • Automatic and manual routing of messages in a custom machine graph.
  • Supports multiple databases (MS SQL Server, MySQL, SQLite, and memory-based storage for now).
  • Supports don’t store, direct send style messaging.
  • Supports Request/Reply style messaging.
  • Easy to use client library to communicate with the DotNetMQ Message Broker.
  • Built-in framework to easily construct RMI services upon message queues.
  • Supports delivering messages to ASP.NET Web Services.
  • GUI-based management and monitoring tool.
  • Easy to install, manage, and use.
  • Written entirely in C# (using .NET Framework 3.5).

I preferred to name DotNetMQ as MDS (Message Delivery System) when first creating it. Because it is designed not just to be a message queue, but also as a system that delivers messages directly to applications and an environment that provides a framework to build application services. I called it DotNetMQ since it is entirely developed using .NET and the DotNetMQ name is more memorable. So, it’s original name (and internal project name) is MDS and the applications have many classes with the prefix MDS.

Why a New Message Broker?

First, I will demonstrate a simple situation where a message broker is needed.

In my experiences in business life, I've observed really bad and uncommon asynchronous enterprise application integration solutions. Usually there is an application that runs on a server and performs some tasks and produces data, and then sends the result data to another application on another server. The second application performs other tasks on the data or evaluates the result (the servers are on the same network or connected over the internet). Also, the message data must be persistent. Even if the remote application is not working or the network is not available, themessage must be delivered on the first chance.

Application - 1 and Application - 2 are executable applications (or Windows services) and Sender Service is a Windows service. Application - 1 performs some task, produces data, and calls a Remote Web Service method onServer - B to transmit data. This Web Service inserts data into a database table. Application - 2 periodically checks the table for new incoming data rows and processes them (and deletes them from the table or marks them as processed to not process the same data again).

If an error occurs during the Web Service call or while processing data in the Web Service, data must not be lost and must be sent later. However, Application - 1 has other tasks to do, so it can not try to send data again and again. It simply inserts data into a database table. Another Windows service (or a thread in Application - 1, if the application always runs) checks this table periodically and tries to send data to the Web Service until data is successfully sent.

This scenario is really reliable (messages are guaranteed to be delivered) but is not an efficient way of communicating between two applications. This solution has some very critical problems:

  • It takes a long time to develop (to code).
  • Individual coding for all message types (or remote method calls). For a new Web Service method call, you must change all the services, applications, and database tables.
  • Almost same software and structures must be developed (or copied and modified) for every similar service.
  • Testing and maintenance of too many services/applications/databases after coding.
  • Some applications and services periodically check the database even if there is no new message (if the database is not well indexed and optimized, this may consume serious system resources).

Message Brokers do all this job and takes all the responsibility to deliver messages to the remote application in the most efficient way. The same application integration using DotNetMQ is shown in the figure below.

DotNetMQ is a standalone Windows service that runs on both Server - A and Server - B. Thus, you just need to write code to communicate with DotNetMQ. Using the DotNetMQ Client Library, it is very easy and fast to connect and send/receive messages to/from the DotNetMQ service. Application - 1 prepares the message, sets the destination, and passes the message to the DotNetMQ Broker. DotNetMQ brokers will deliver the message toApplication - 2 in the most efficient and fastest way.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MQ与Webservice的区别 的相关文章

  • Spring Boot集成webService

    服务端 使用idea创建spring boot工程 xff1a File New Project Spring Initializr 在pom添加依赖 span class hljs tag span class hljs tag lt s
  • WebService实例

    一 发布webservice服务 1 编写服务接口 package com nari test webservice import javax jws WebMethod import javax jws WebParam import j
  • WebService案例实例

    WebService案例实例 前言 xff1a 由于工作需要 xff0c 写一个接口 xff0c 返回xml信息 供其他服务调用 最初使用python 43 flask框架 xff0c 能够返回出正确的xml信息 xff0c 似乎调用这个接
  • cxf+spring实现webservice

    1 构建maven项目 xff0c 工程结构如下 xff1a 这里需要特别指出就是cxf core 3 1 12 jar类路径META INF cxf下有一个cxf xml的配置文件 xff0c 这个在applicationContext
  • 使用CXF和camel-cxf调用webservice

    CXF是什么 Apache CXF 是一个开源的 全功能的WebService框架 xff0c 它提供了一套工具和API来帮助开发和构建WebService xff0c 像 JAX WS 和 JAX RS 它也支持许多WebService标
  • SQL Server调用WebAPI和WebService

    SQLSERVER调用WebAPI和WebServiceSqlServer调用webapi和webService接口 declare 64 url nvarchar max set 64 url 61 39 http XXX GetToke
  • 最隐晦的程序设计指引

    一 百家争鸣 俗话说 程序员半年不学新东西 就变奥特曼 out man 过时之人 了 IT行业可以说是变化最快的行业 每年都有大量的新概念 新术语 新技术被创造出来 在多数人还在一头雾水时 更好的 替代品又被创造出来 别的不说了 单说设计方
  • 使用gSOAP与WebService - 第一部分 为VC++从WSDL读取信息

    CurrencyConvertor How use gSOAP and WebServices Part 1 Get ready with VC 6 from WSDL file Download Demo 42 1 KB Download
  • Java web实现简登录页面(MyBatis+jsp+servlet+html+css+javascript)附源码

    本文利用MyBatis jsp servlet html css javascript实现了一个简单的登录页面 对用户输入的用户名和密码就行校验 校验通过则登录成功 密码和用户信息保存在mysql表中 通过MyBatis访问 MyBatis
  • WebService+Rxjava

    最近公司有了个新项目 是之前有个项目需要迭代 由于这个项目比较老 所以用的是WebService的接口 我之前都是写的是restful的接口 没有接触过WebServiece 看到之前的代码我也有点闷逼 于是就花了几天去研究了下WebSer
  • 彻底理解webservice SOAP WSDL

    WebServices简介 先给出一个概念 SOA 即Service Oriented Architecture 中文一般理解为面向服务的架构 既然说是一种架构的话 所以一般认为 SOA 是包含了运行环境 编程模型 架构风格和相关方法论等在
  • SpringBoot 发布webservice接口,实现接口如何调用业务层代码

    如果直接按照业务层方式 在webservice实现是不可行的 Autowired无法自动注入 还会报空指针的错误 因为在webservice的自动注入不是在spring容器中找bean对象 所以按照service层方式是无法取得对象 所以我
  • Java调用WebService接口的四种方式

    调用WebService 使用wsimport生成代码 不推荐 使用Axis 1 4 动态调用 使用HTTP SOAP方式远程调用 通过Spring注解方式调用 使用wsimport生成代码 不推荐 配置java环境变量后在命令窗口中输入
  • C#怎么测试静态方法?我给出了2种方案

    问题 假设有一个方法需要判断当前小时范围 代码如下 public class Class1 public bool SomeMethod var hour DateTime Now Hour if hour gt 9 hour lt 12
  • c#对接webservice接口

    方式一 需要填写地址 不能映射每个方法 工具类 using System using System CodeDom Compiler using System CodeDom using System Collections Generic
  • 使用gSOAP与WebService - 第二部分 开发第一个WebService客户端(C++)

    CurrencyConvertor How use gSOAP and WebServices Part 2 Doing the first WS client Download Demo Project 42 1 KB Download
  • WebService代码

    http git oschina net huangyong cxf demo
  • CXF开发WebService客户端

    开发必备 1 apache cxf 2 2 6 2 spring ws 1 5 8 3 eclipse jee galileo SR1 win32 开发步骤 一 新建一个普通的java工程 名字叫WebService CXF Client
  • WebService 之 WSDL文件 讲解 .

    一 WSDL概述 WebServices Description Language WSDL Web服务语言 是一个用于精确描述Web Service的文档格式 WSDL非常适合于用作代码生成器 它能够读取WSDL文档 并且可以为访问Web
  • ORA-28002: 7 天之后口令将过期的解决方法 .

    启动Tomcat 当连接oracle数据库时错误信息提示 ORA 28002 7 天之后口令将过期 原因 oracle11g中默认在default概要文件中设置了 PASSWORD LIFE TIME 180 所导致 oracle用户的密码

随机推荐

  • git 修改commit的名字与撤回提交

    当你不小心 xff0c 写错了提交的注视 信息 xff0c 该如何处理呢 理论上 xff0c SCM是不应该修改历史的信息的 xff0c 提交的注释也是 不过在git中 xff0c 其commit提供了一个 amend参数 xff0c 可以
  • SQLAlchemy 的 scoped_session

    SQLAlchemy 的 scoped session 是啥玩意 通常我们用 SQLAlchemy 写数据的时候要创建 Session 对象来维护数据库会话 xff0c 用完了再关掉 但是听说还有个叫scoped session的玩意 xf
  • python 的StringIO

    1 IO的含义 在计算机中 xff0c IO是Input Output的简写 xff0c 也就是输入和输出 由于程序和运行时数据是在内存中驻留 xff0c 由CPU这个超快的计算核心来执行 xff0c 涉及到数据交换的地方 xff0c 通常
  • python 的fcntl模块

    python 中给文件加锁 fcntl模块 import fcntl 打开一个文件 f 61 open 39 test 39 当前目录下test文件要先存在 xff0c 如果不存在会报错 对该文件加密 xff1a fcntl flock f
  • Jmeter添加MD5方法插件

    1 xff1a 下载 https jmeter plugins org install Install 2 xff1a jmeter plugins manager 1 3 jar放到 apache jmeter 5 0 lib ext目录
  • sql 语句 将查询结果中数字等标示转成汉字

    使用case 语句 将sex 字段进行转换 0 1 2 男 xff0c 女 xff0c 未知 SELECT u userid u username CASE u sex WHEN 0 THEN 39 女 39 WHEN 1 THEN 39
  • linux的more命令

    more命令 xff0c 功能类似 cat xff0c cat命令是整个文件的内容从上到下显示在屏幕上 more会以一页一页的显 示方便使用者逐页阅读 xff0c 而最基本的指令就是按空白键 xff08 space xff09 就往下一页
  • docker入门实例

    1 image文件 Docker 把应用程序及其依赖 xff0c 打包在 image 文件里面 只有通过这个文件 xff0c 才能生成 Docker 容器 image 文件可以看作是容器的模板 Docker 根据 image 文件生成容器的
  • vim批量替换&行首尾增加&删除列

    删除列 删除列的方法 xff1a 1 ctrl 43 v 这样会启动可视模式 xff0c 按 j k 可以发现它能够在一列上面选中字符 2 按下 G 这样可以从文本的第一行选中到最后一行 3 按下 x 就会把这一列删掉 行首尾替换 xff1
  • vim 支持 python

    https www jianshu com p 3e606e31da5f 前段时间刚玩linux时为了图个简单打算直接用vim来写python代码省得再下个软件 xff08 好吧 xff0c 其实是自己下了好多次都失败了 xff0c 一气之
  • 用户态和核心态的概念以及为什么要区别?以及两者之间的切换

    一 用户态和核心态的概念 用户态 xff1a 内核态与用户态是操作系统的两种运行级别 当程序运行在3级特权级上时 xff0c 就可以称之为运行在用户态 xff0c 因为这是最低特权级 xff0c 是普通的用户进程运行的特权级 xff0c 大
  • strstr(str1,str2)函数使用时注意事项

    可能有的人还没听过strstr函数 xff0c 个人认为这个一个很实用的函数 xff0c strstr str1 str2 函数是字符串处理函数之一 xff0c 位于头文件 string h 中 对于处理字符串的一些问题有很大的帮助 定义
  • Java This 的用法

    JAVA This的用法 先写一个要调用的类 都放在名为test的包下面 在这里插入代码片package test span class token keyword public span span class token keyword
  • 关于松耦合和紧耦合的理解

    松耦合系统通常是基于消息的系统 xff0c 此时客户端和远程服务并不知道对方是如何实现的 客户端和服务之间的通讯由消息的架构支配 只要消息符合协商的架构 xff0c 则客户端或服务的实现就可以根据需要进行更改 xff0c 而不必担心会破坏对
  • 第六篇 键盘中断与应用程序读取键盘缓冲区

    这篇博文主要介绍在X86下键盘的中断过程 xff0c 以及应用程序如何利用中断读取键盘缓冲区内容 一 撰写该篇博文的背景介绍 在我们全屏看视频时 xff0c 按下Esc键 xff0c 播放器还原或者最小化 xff1b 在利用其他软件的时候
  • 发现一个aruco在线生成器,可以在线生成aruco CharucoBoard GridBoard AprilTag 图片, 真香

    最近在研究 opencv 检测 aruco标记项目 xff0c 想弄点aruco标记码来测试 xff0c 发现网上很少在线生成aruco标记码的工具 xff0c 导致在做测试时候浪费了很多时间去搞这个码 xff0c 基本上大家都用 xff0
  • FreeRTOS基础六:中断管理1

    嵌入式实时系统需要对外界的某个事件做出及时的响应动作 例如串口外设收到了一帧数据后 xff0c 需要通知数据解析任务 xff0c 同时还要将数据帧传递给解析任务 xff0c 完成数据的处理 设计出一种好的策略来完成这个过程时需要考虑以下几个
  • FreeRTOS基础四:队列

    简介 FreeRTOS中的队列是一种用于实现 任务与任务 xff0c 任务与中断 以及 中断与任务 之间的通信 机制 此外 xff0c 任务从队列读数据或者写入数据到队列时 xff0c 都可能被阻塞 这个特性使得任务可以被设计成基于事件驱动
  • FreeRTOS基础二:堆内存管理之heap_4方案

    背景知识 从FreeRTOS V9 0 0内核版本开始 xff0c 内核对象占用的内存可以在编译期间静态分配 xff0c 也可以在运行期间动态分配 内核对象如 xff1a tasks xff08 任务 xff09 xff0c queues
  • MQ与Webservice的区别

    Webservice 和MQ MessageQueue 都是解决跨平台通信的常用手段 xff0c 两者有哪些区别呢 xff1f 个人认为最本质的区别在于 Webservice近乎实时通信 xff0c 而MQ却通常是延时通信 什么意思呢 xf