Commit 2822d3ad authored by levi's avatar levi
Browse files

fixed docker network composes, rmq changes

parent f7c311ad
......@@ -26,10 +26,11 @@ ARG OVERLAY_WS
WORKDIR $OVERLAY_WS
COPY --from=cacher /tmp/$OVERLAY_WS/src ./src
RUN . /opt/ros/$ROS_DISTRO/setup.sh
RUN apt-get update && rosdep install -y \
RUN apt-get update && apt-get install -y python3-pip && rosdep install -y \
--from-paths src/ \
--ignore-src \
&& rm -rf /var/lib/apt/lists/*
RUN python3 -m pip install pika
# build overlay source
COPY --from=cacher $OVERLAY_WS/src ./src
......
ARG FROM_IMAGE=osrf/ros:foxy-desktop
ARG FROM_IMAGE=ros:foxy
ARG OVERLAY_WS=/opt/ros/overlay_ws
# multi-stage for caching
......@@ -26,10 +26,11 @@ ARG OVERLAY_WS
WORKDIR $OVERLAY_WS
COPY --from=cacher /tmp/$OVERLAY_WS/src ./src
RUN . /opt/ros/$ROS_DISTRO/setup.sh
RUN apt-get update && rosdep install -y \
RUN apt-get update && apt-get install -y python3-pip && rosdep install -y \
--from-paths src/ \
--ignore-src \
&& rm -rf /var/lib/apt/lists/*
RUN python3 -m pip install pika
# build overlay source
COPY --from=cacher $OVERLAY_WS/src ./src
......
version: '3'
# networks:
# drobotti:
# driver: bridge
services:
# ubuntu:
# container_name: ubuntu
# build:
# context: ./ubuntu-network-test
# restart: always
# network_mode: bridge
# network_mode: host
# networks:
# - drobotti
rmq_server:
container_name: rmq-srv
build:
context: ../
dockerfile: ./docker/rmq-server/rmq_server.Dockerfile
restart: always
network_mode: host
# networks:
# - drobotti
# ports:
# - 5672:5672
# - 15672:15672
# - 1883:1883
# teleop_terminal:
# container_name: teleop
# build:
# context: ../
# dockerfile: ./docker/teleop-terminal/teleop_terminal.Dockerfile
# restart: always
# networks:
# - drobotti
# stdin_open: true # docker run -i
# tty: true # docker run -t
# rmq_publisher:
# container_name: rmq-pub
# build:
# context: ../
# dockerfile: ./docker/rmq-publisher/rmq_publisher.Dockerfile
# depends_on:
# - rmq_server
# # - teleop_terminal
# restart: always
# network_mode: host
# # networks:
# # - drobotti
network_mode: bridge
ports:
- 5672:5672
- 15672:15672
- 1883:1883
teleop_terminal:
container_name: teleop
build:
context: ../
dockerfile: ./docker/teleop-terminal/teleop_terminal.Dockerfile
restart: always
stdin_open: true # docker run -i
tty: true # docker run -t
rmq_publisher:
container_name: rmq-pub
build:
context: ../
dockerfile: ./docker/rmq-publisher/rmq_publisher.Dockerfile
depends_on:
- rmq_server
restart: always
network_mode: bridge
rmq_subscriber:
container_name: rmq-sub
build:
......@@ -56,15 +36,10 @@ services:
dockerfile: ./docker/rmq-subscriber/rmq_subscriber.Dockerfile
depends_on:
- rmq_server
# - teleop_terminal
restart: always
network_mode: host
# networks:
# - drobotti
network_mode: bridge
ros2_multicast_receive:
container_name: ros2-multi
build: ./ros2-multicast-test
restart: always
network_mode: host
# networks:
# - drobotti
\ No newline at end of file
network_mode: bridge
\ No newline at end of file
......@@ -8,8 +8,8 @@ rmq_subscriber:
rmq_publisher_docker:
ros__parameters:
server_hostname: "127.0.0.1" #containername
server_hostname: "172.17.0.1" #bridge gateway
rmq_subscriber_docker:
ros__parameters:
server_hostname: "127.0.0.1" #containername
\ No newline at end of file
server_hostname: "172.17.0.1" #bridge gateway
\ No newline at end of file
sudo apt install python3-pika
\ No newline at end of file
......@@ -12,8 +12,6 @@
<depend>sensor_msgs</depend>
<depend>std_msgs</depend>
<depend>python3-pika</depend>
<test_depend>python3-pytest</test_depend>
<export>
......
# apt requirements
the resdep is outdated on the pika package which is using the old one 0.9.x.. (python3-pika)
use pika instead
```
apt install pika
```
(pika v1.2.0)[https://pypi.org/project/pika/]
\ No newline at end of file
......@@ -117,6 +117,7 @@ class RabbitMQPublisher(Node):
def init_rabbitmq(self):
self.get_logger().info("Initializing Connection")
time.sle
for i in range(5):
try:
self.rmq_connection = pika.BlockingConnection(
......
......@@ -79,9 +79,11 @@ class RabbitMQSubscriber(Node):
def start_consumer(self):
self.get_logger().info("Initializing Connection")
time.sleep(5)
for i in range(5):
try:
self.rmq_connection = pika.BlockingConnection(
pika.ConnectionParameters(self.get_parameter('server_hostname').get_parameter_value().string_value)
pika.ConnectionParameters(host=self.get_parameter('server_hostname').get_parameter_value().string_value)
)
self.rmq_channel = self.rmq_connection.channel()
self.rmq_channel.exchange_declare(
......@@ -95,17 +97,20 @@ class RabbitMQSubscriber(Node):
queue=queue_name,
routing_key="desktoprobotti.from_cosim")
self.rmq_channel.basic_consume(
queue=queue_name,
on_message_callback=self.on_msg_received,
auto_ack=True)
self.rmq_channel.basic_consume(queue=queue_name, on_message_callback=self.on_msg_received, auto_ack=True)
except Exception as err:
if i == 0:
self.get_logger().info("RabbitMQ Initialization failed. Is rabbitmq running?")
self.get_logger().info(err)
self.get_logger().info(f"Retrying... (try {i+1} out of 5)")
time.sleep(1)
else:
self.get_logger().info("RabbitMQ Initialization Complete!")
self.rmq_channel.start_consuming()
else:
self.get_logger().info("Exiting")
self.exit()
def init_rabbitmq(self):
consumer_thread = threading.Thread(target=self.start_consumer)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment