org.eclipse.dirigible.components.api.rabbitmq.RabbitMQReceiverRunner Maven / Gradle / Ivy
/*
* Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
*
* All rights reserved. This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible
* contributors SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.dirigible.components.api.rabbitmq;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.dirigible.components.engine.javascript.service.JavascriptService;
import org.eclipse.dirigible.repository.api.RepositoryPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Consumer;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import org.springframework.beans.factory.annotation.Autowired;
/**
* The Class RabbitMQReceiverRunner.
*/
public class RabbitMQReceiverRunner implements Runnable {
/**
* The Constant logger.
*/
private static final Logger logger = LoggerFactory.getLogger(RabbitMQReceiverRunner.class);
/**
* The Constant DIRIGIBLE_MESSAGING_WRAPPER_MODULE_ON_MESSAGE.
*/
private static final String DIRIGIBLE_MESSAGING_WRAPPER_MODULE_ON_MESSAGE = "messaging/wrappers/onMessage.js";
/**
* The Constant DIRIGIBLE_MESSAGING_WRAPPER_MODULE_ON_ERROR.
*/
private static final String DIRIGIBLE_MESSAGING_WRAPPER_MODULE_ON_ERROR = "messaging/wrappers/onError.js";
/**
* The connection.
*/
private final Connection connection;
/**
* The channel.
*/
private final Channel channel;
/**
* The queue.
*/
private final String queue;
/**
* The handler.
*/
private final String handler;
/**
* The stopped.
*/
private final AtomicBoolean stopped = new AtomicBoolean(false);
@Autowired
private JavascriptService javascriptService;
/**
* Instantiates a new rabbit MQ receiver runner.
*
* @param connection the connection
* @param channel the channel
* @param queue the queue
* @param handler the handler
*/
public RabbitMQReceiverRunner(Connection connection, Channel channel, String queue, String handler) {
this.connection = connection;
this.channel = channel;
this.queue = queue;
this.handler = handler;
}
/**
* Start the consumer.
*/
@Override
public void run() {
try {
if (logger.isInfoEnabled()) {
logger.info("Starting a RabbitMQ receiver for: " + this.queue);
}
channel.queueDeclare(queue, false, false, false, null);
while (!stopped.get()) {
Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy