Activemq la gi

Flexible & Powerful Open Source
Multi-Protocol Messaging

Activemq la gi

Apache ActiveMQ® is the most popular open source, multi-protocol, Java-based message broker. It supports industry standard protocols so users get the benefits of client choices across a broad range of languages and platforms. Connect from clients written in JavaScript, C, C++, Python, .Net, and more. Integrate your multi-platform applications using the ubiquitous AMQP protocol. Exchange messages between your web applications using STOMP over websockets. Manage your IoT devices using MQTT. Support your existing JMS infrastructure and beyond. ActiveMQ offers the power and flexibility to support any messaging use-case.

ActiveMQ 5.17.3 Release

Maintenance release on 5.17.x series, containing Spring 5.3.23, Log4J 2.19.0, and a lot of other fixes and improvements....more

Dec 4th, 2022

There are currently two "flavors" of ActiveMQ available - the well-known "classic" broker and the "next generation" broker code-named Artemis. Once Artemis reaches a sufficient level of feature parity with the "Classic" code-base it will become the next major version of ActiveMQ. Initial migration documentation is available as well as a development roadmap for Artemis.

ActiveMQ "Classic"

Long established, endlessly pluggable architecture serving many generations of applications.

  • JMS 1.1 with full client implementation including JNDI
  • High availability using shared storage
  • Familiar JMS-based addressing model
  • "Network of brokers" for distributing load
  • KahaDB & JDBC options for persistence

Find out more Download Latest

ActiveMQ Artemis

High-performance, non-blocking architecture for the next generation of messaging applications.

  • JMS 1.1 & 2.0 + Jakarta Messaging 2.0 & 3.0 with full client implementations including JNDI
  • High availability using shared storage or network replication
  • Simple & powerful protocol agnostic addressing model
  • Flexible clustering for distributing load
  • Advanced journal implementations for low-latency persistence as well as JDBC
  • High feature parity with ActiveMQ "Classic" to ease migration
  • Asynchronous mirroring for disaster recovery
  • Data Driven Load Balance

Find out more Download Latest

Protect your data & Balance your Load

ActiveMQ provides many advanced features including message load-balancing and high-availability for your data. Multiple connected "master" brokers can dynamically respond to consumer demand by moving messages between the nodes in the background. Brokers can also be paired together in a master-slave configuration so that if a master fails then the slave takes over ensuring clients can get to their important data and eliminating costly downtime.

Easy Enterprise Integration Patterns

Enterprise Integration Patterns describe the various ways in which multiple applications generally interact and integrate with each other. Aysnchronous messaging is at the heart of this integration, and ActiveMQ makes it easy to leverage these patterns via Apache Camel routes deployed directly on the broker.

Flexible Deployment

ActiveMQ is most commonly deployed as a standalone process. This option isolates ActiveMQ from any particular application and provides maximum flexibility for resource allocation and management. However, ActiveMQ can be configured to have a very small footprint which makes it viable to embed it within your application. This option can provide an application with simple, powerful messaging semantics and also allow easy message exchange with other applications.

  • Techblog
  • Thủ thuật

Activemq la gi

Khi bạn thiết kế và xây dựng các ứng dụng ở quy mô lớn, bạn phải đối mặt với hai thách thức quan trọng: khả năng mở rộng và tính mạnh mẽ. Do vậy bạn cần thiết kế dịch vụ cho riêng mình để ngay cả khi nó phải chịu tải nặng không liên tục thì ứng dụng vẫn tiếp tục hoạt động một cách đáng tin cậy.

Do vậy, hãy theo dõi bài viết dưới đây của Bizfly Cloud để biết cách mở rộng quy mô dịch vụ nhỏ với Message Queues, Spring Boot and Kubernetes.

Ví dụ thực tế Apple Store

Mỗi năm có hàng triệu khách hàng của Apple đăng ký trước để mua một chiếc iPhone mới. Nghĩa là sẽ có hàng triệu người mua một mặt hàng cùng một lúc.

Lúc này nếu bạn định hình lưu lượng truy cập của cửa hàng Apple dưới dạng yêu cầu mỗi giây theo thời gian, thì biểu đồ có thể trông như thế này:

Bây giờ hãy tưởng tượng bạn được giao nhiệm vụ với thử thách xây dựng ứng dụng như vậy.

Bạn xây dựng một microservice để hiển thị các trang web và cung cấp các nội dung tĩnh.

Lúc này bạn cũng xây dựng một API REST phụ trợ để xử lý các yêu cầu đến và hai thành phần được tách biệt vì với cùng một API REST, bạn có thể phân phát trang web và ứng dụng dành cho thiết bị di động.

Bạn quyết định chia tỷ lệ ứng dụng thành bốn phiên bản cho giao diện người dùng và bốn phiên bản cho phụ trợ vì bạn dự đoán trang web sẽ bận rộn hơn bình thường.

Các dịch vụ đầu cuối đang xử lý.

Bạn nhận thấy rằng phần phụ trợ được kết nối với cơ sở dữ liệu đang phải vật lộn để theo kịp số lượng giao dịch.

Lúc này bạn có thể mở rộng số lượng bản sao lên 8 cho chương trình hỗ trợ.

Ứng dụng không có tính khả dụng cao

- Front-end và backend được kết hợp chặt chẽ - trên thực tế, nó không thể xử lý các ứng dụng mà không có backend

- Giao diện người dùng và phần phụ trợ phải mở rộng quy mô - nếu không có đủ phần phụ trợ website có thể bị ngưng kết nối.

- Nếu chương trình phụ trợ không khả dụng, bạn không thể xử lý các giao dịch đến.

Và một điều hiển nhiên là các giao dịch bị mất sẽ dẫn đến tình trạng doanh thu giảm. Lúc này doanh nghiệp sẽ cần làm gì?

Mã hóa ứng dụng Spring

Dịch vụ này có ba thành phần: front-end, backend và message broker.

Ứng dụng Spring có:

- Một trang chủ nơi bạn có thể mua các mặt hàng

- Bảng điều khiển quản trị nơi bạn có thể kiểm tra số lượng thư trong queue

- Một /health điểm cuối để báo hiệu khi ứng dụng sẵn sàng nhận lưu lượng truy cập

- Một /submit điểm cuối nhận gửi từ biểu mẫu và tạo thông báo trong queue

- Một /metrics điểm cuối để hiển thị số lượng thư đang chờ xử lý trong queue

Ứng dụng có thể hoạt động ở hai chế độ:

1. Giao diện người dùng:

Activemq la gi

2. Nhân viên quản trị cửa hàng:

Activemq la gi

Bạn có thể định cấu hình ứng dụng ở một trong hai chế độ, bằng cách thay đổi các giá trị trong application.yaml.

Gửi và nhận tin nhắn với JMS

Spring JMS (Java Message Service) là một cơ chế mạnh mẽ để gửi và nhận tin nhắn bằng các giao thức chuẩn. 

Trình môi giới tin nhắn phổ biến nhất mà bạn có thể sử dụng với JMS là ActiveMQ - một máy chủ nhắn tin mã nguồn mở.

Với hai thành phần đó, bạn có thể xuất bản tin nhắn lên queue (ActiveMQ) bằng giao diện quen thuộc (JMS) và sử dụng cùng một giao diện để nhận tin nhắn. Hơn thế nữa, Spring Boot có tích hợp tuyệt vời với JMS để bạn có thể bắt kịp tốc độ nhanh chóng.

Trên thực tế, lớp sau đây được sử dụng để tương tác với queues:

QueueService.java

@Component

public class QueueService implements MessageListener {

  private static final Logger LOGGER = LoggerFactory.getLogger(QueueService.class);

  @Autowired

  private JmsTemplate jmsTemplate;

  public void send(String destination, String message) {

    LOGGER.info("sending message='{}' to destination='{}'", message, destination);

    jmsTemplate.convertAndSend(destination, message);

  }

  @Override

  public void onMessage(Message message) {

    if (message instanceof ActiveMQTextMessage) {

      ActiveMQTextMessage textMessage = (ActiveMQTextMessage) message;

      try {

        LOGGER.info("Processing task " + textMessage.getText());

        Thread.sleep(5000);

        LOGGER.info("Completed task " + textMessage.getText());

      } catch (InterruptedException e) {

        e.printStackTrace();

      } catch (JMSException e) {

        e.printStackTrace();

      }

    } else {

      LOGGER.error("Message is not a text message " + message.toString());

    }

  }

}

Bạn có thể xử lý thông báo trong nền bằng cách đăng ký trình nghe trong ứng dụng Spring Boot như sau:

SpringBootApplication.java

@SpringBootApplication

@EnableJms

public class SpringBootApplication implements JmsListenerConfigurer {

  @Autowired

  private QueueService queueService;

  public static void main(String[] args) {

    SpringApplication.run(SpringBootApplication.class, args);

  }

  @Override

  public void configureJmsListeners(JmsListenerEndpointRegistrar registrar) {

    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();

    endpoint.setId("myId");

    endpoint.setDestination("queueName");

    endpoint.setMessageListener(queueService);

    registrar.registerEndpoint(endpoint);

  }

}

Trong đó id là số nhận dạng duy nhất cho người tiêu dùng và đích là tên của queue.

Triển khai ứng dụng cho Kubernetes

Ứng dụng có ba thành phần:

- Ứng dụng Spring Boot hiển thị giao diện người dùng

- ActiveMQ như một nhà môi giới tin nhắn

- Chương trình phụ trợ Spring Boot xử lý các giao dịch

Để mang lại hiệu quả bạn nên triển khai ba thành phần riêng biệt.

Ngoài ra, bạn nên tạo:

- Một triển khai đối tượng mô tả những gì chứa được triển khai và cấu hình của nó

- Một dịch vụ đối tượng mà hoạt động như một cân bằng tải cho tất cả các trường hợp của ứng dụng được tạo ra bởi Deployment

Triển khai ActiveMQ

Tạo một activemq-deployment.yaml tệp với nội dung sau:

activemq-deploy.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

  name: queue

spec:

  replicas: 1

  selector:

    matchLabels:

      app: queue

  template:

    metadata:

      labels:

        app: queue

    spec:

      containers:

      - name: web

        image: webcenter/activemq:5.14.3

        imagePullPolicy: IfNotPresent

        ports:

          - containerPort: 61616

        resources:

          limits:

            memory: 512Mi

Tạo một activemq-service.yaml tệp với nội dung sau:

activemq-service.yaml

apiVersion: v1

kind: Service

metadata:

  name: queue

spec:

  ports:

    - port: 61616

      targetPort: 61616

  selector:

    app: queue

Kết luận

Việc thiết kế các ứng dụng ở quy mô lớn đòi hỏi phải lập kế hoạch và thử nghiệm cẩn thận. Kiến trúc dựa trên queue là một mẫu thiết kế tuyệt vời để tách các microservices của bạn và đảm bảo chúng có thể được mở rộng và triển khai độc lập.

Và trong khi bạn có thể triển khai các tập lệnh triển khai của mình, thì việc tận dụng một container orchestration như Kubernetes để triển khai và mở rộng các ứng dụng của bạn một cách tự động sẽ dễ dàng hơn.

Bizfly Cloud hiện đang là nhà cung cấp các dịch vụ máy chủ đám mây tốt nhất Việt Nam. Hiện nay có rất nhiều doanh nghiệp lớn đang sử dụng dịch vụ máy chủ đám mây của chúng tôi như:  Vingroup, VTV, Thu Cúc, Ahamove, VNtrip, Sapo, SSI... Quý khách hàng quan tâm hãy liên hệ ngay với công ty để nhận được hỗ trợ và tư vấn sớm nhất nhé. Cảm ơn bạn đã theo dõi bài viết.