• 周五. 12月 9th, 2022

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

Java JMS minimalist demo

[db:作者]

1月 6, 2022

This article is clear enough to explain JMS The main idea of the model . Now? ,Message Broker It’s an essential part of almost every enterprise application . Source code used Located here .

JMS or Java Messaging A service is a way of using messages ( object ) Conduct asynchronous Communication solutions . first , It is JSR(Java EE Specifications used in ) Part of .

Suppose we have any service that can only process 100 A request . Any higher load will block or stop the service .

Such problems are well known , It can be done by putting API Split into two parts to sort easily :

  • The first part creates a task and immediately returns it id. Once the system has available staff , It will handle the task .
  • API The second part of is continuously pooled by users , Until the mission is completed and back .

So the key to our problem is how to 2 individual API Sharing information between ? We might use databases or some Java aggregate , but JMS Two convenient asynchronous solutions are provided .

stay Jms There are two main models in this model : Queues and topics . The key difference is in The theme Topic We can have a lot of subscribers in . Both structures can receive data from many producers . 

There are many known message agents , Such as RabbitMq、Kafka etc. . In our example , We use free open source Active MQ agent . To install it , Please perform the following steps :

  • 1. download ActiveMQ  Classic.
  • 2. install Java And will JAVA_HOME Add to PATH.
  • 3、 stay apache-activemq-5.16.2\bin\win64 perform wrapper.exe.
  • 4. open http://localhost:8161/admin/index.jsp.
  • 5. Create a queue in the tab queue by pressing the Create button .
<dependency>
  <groupId>org.apache.activemq</groupId>
  <artifactId>activemq-core</artifactId>
  <version>5.7.0</version>
</dependency>

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注