rabbitmq on docker + ssh port forward = local rabbitmq
rabbitmq on docker + ssh port forward = local rabbitmq
目录
set up a rabbit mq server on a remote server named openwrt
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq
set up port forward on windows
inspired by remote port forward on VSCODE
ssh -L 5672:127.0.0.1:5672 openwrt -N -v -v
access rabbit mq server as if it is on windows
// Recv.java
// https://github.com/rabbitmq/rabbitmq-tutorials/blob/master/java/Send.java
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;
public class Recv {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), "UTF-8");
System.out.println(" [x] Received '" + message + "'");
};
channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> { });
}
}
// Send.java
// https://github.com/rabbitmq/rabbitmq-tutorials/blob/master/java/Recv.java
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.nio.charset.StandardCharsets;
public class Send {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
try (Connection connection = factory.newConnection();
Channel channel = connection.createChannel()) {
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes(StandardCharsets.UTF_8));
System.out.println(" [x] Sent '" + message + "'");
}
}
}
run Recv.java first
then run Send.java
switch back to Recv.java
references
Downloading and Installing RabbitMQ — RabbitMQ
[macos - How does VSCode Remote Development] [Forward Port] work? - Stack Overflow
networking - ssh tunnel refusing connections with "channel 2: open failed" - Server Fault