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 ...@@ -26,10 +26,11 @@ ARG OVERLAY_WS
WORKDIR $OVERLAY_WS WORKDIR $OVERLAY_WS
COPY --from=cacher /tmp/$OVERLAY_WS/src ./src COPY --from=cacher /tmp/$OVERLAY_WS/src ./src
RUN . /opt/ros/$ROS_DISTRO/setup.sh 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/ \ --from-paths src/ \
--ignore-src \ --ignore-src \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN python3 -m pip install pika
# build overlay source # build overlay source
COPY --from=cacher $OVERLAY_WS/src ./src 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 ARG OVERLAY_WS=/opt/ros/overlay_ws
# multi-stage for caching # multi-stage for caching
...@@ -26,10 +26,11 @@ ARG OVERLAY_WS ...@@ -26,10 +26,11 @@ ARG OVERLAY_WS
WORKDIR $OVERLAY_WS WORKDIR $OVERLAY_WS
COPY --from=cacher /tmp/$OVERLAY_WS/src ./src COPY --from=cacher /tmp/$OVERLAY_WS/src ./src
RUN . /opt/ros/$ROS_DISTRO/setup.sh 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/ \ --from-paths src/ \
--ignore-src \ --ignore-src \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN python3 -m pip install pika
# build overlay source # build overlay source
COPY --from=cacher $OVERLAY_WS/src ./src COPY --from=cacher $OVERLAY_WS/src ./src
......
version: '3' version: '3'
# networks:
# drobotti:
# driver: bridge
services: services:
# ubuntu:
# container_name: ubuntu
# build:
# context: ./ubuntu-network-test
# restart: always
# network_mode: bridge
# network_mode: host
# networks:
# - drobotti
rmq_server: rmq_server:
container_name: rmq-srv container_name: rmq-srv
build: build:
context: ../ context: ../
dockerfile: ./docker/rmq-server/rmq_server.Dockerfile dockerfile: ./docker/rmq-server/rmq_server.Dockerfile
restart: always restart: always
network_mode: host network_mode: bridge
# networks: ports:
# - drobotti - 5672:5672
# ports: - 15672:15672
# - 5672:5672 - 1883:1883
# - 15672:15672 teleop_terminal:
# - 1883:1883 container_name: teleop
# teleop_terminal: build:
# container_name: teleop context: ../
# build: dockerfile: ./docker/teleop-terminal/teleop_terminal.Dockerfile
# context: ../ restart: always
# dockerfile: ./docker/teleop-terminal/teleop_terminal.Dockerfile stdin_open: true # docker run -i
# restart: always tty: true # docker run -t
# networks: rmq_publisher:
# - drobotti container_name: rmq-pub
# stdin_open: true # docker run -i build:
# tty: true # docker run -t context: ../
# rmq_publisher: dockerfile: ./docker/rmq-publisher/rmq_publisher.Dockerfile
# container_name: rmq-pub depends_on:
# build: - rmq_server
# context: ../ restart: always
# dockerfile: ./docker/rmq-publisher/rmq_publisher.Dockerfile network_mode: bridge
# depends_on:
# - rmq_server
# # - teleop_terminal
# restart: always
# network_mode: host
# # networks:
# # - drobotti
rmq_subscriber: rmq_subscriber:
container_name: rmq-sub container_name: rmq-sub
build: build:
...@@ -56,15 +36,10 @@ services: ...@@ -56,15 +36,10 @@ services:
dockerfile: ./docker/rmq-subscriber/rmq_subscriber.Dockerfile dockerfile: ./docker/rmq-subscriber/rmq_subscriber.Dockerfile
depends_on: depends_on:
- rmq_server - rmq_server
# - teleop_terminal
restart: always restart: always
network_mode: host network_mode: bridge
# networks:
# - drobotti
ros2_multicast_receive: ros2_multicast_receive:
container_name: ros2-multi container_name: ros2-multi
build: ./ros2-multicast-test build: ./ros2-multicast-test
restart: always restart: always
network_mode: host network_mode: bridge
# networks: \ No newline at end of file
# - drobotti
\ No newline at end of file
...@@ -8,8 +8,8 @@ rmq_subscriber: ...@@ -8,8 +8,8 @@ rmq_subscriber:
rmq_publisher_docker: rmq_publisher_docker:
ros__parameters: ros__parameters:
server_hostname: "127.0.0.1" #containername server_hostname: "172.17.0.1" #bridge gateway
rmq_subscriber_docker: rmq_subscriber_docker:
ros__parameters: ros__parameters:
server_hostname: "127.0.0.1" #containername server_hostname: "172.17.0.1" #bridge gateway
\ No newline at end of file \ No newline at end of file
sudo apt install python3-pika
\ No newline at end of file
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
<depend>geometry_msgs</depend> <depend>geometry_msgs</depend>
<depend>sensor_msgs</depend> <depend>sensor_msgs</depend>
<depend>std_msgs</depend> <depend>std_msgs</depend>
<depend>python3-pika</depend>
<test_depend>python3-pytest</test_depend> <test_depend>python3-pytest</test_depend>
......
# 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): ...@@ -117,6 +117,7 @@ class RabbitMQPublisher(Node):
def init_rabbitmq(self): def init_rabbitmq(self):
self.get_logger().info("Initializing Connection") self.get_logger().info("Initializing Connection")
time.sle
for i in range(5): for i in range(5):
try: try:
self.rmq_connection = pika.BlockingConnection( self.rmq_connection = pika.BlockingConnection(
......
...@@ -79,33 +79,38 @@ class RabbitMQSubscriber(Node): ...@@ -79,33 +79,38 @@ class RabbitMQSubscriber(Node):
def start_consumer(self): def start_consumer(self):
self.get_logger().info("Initializing Connection") self.get_logger().info("Initializing Connection")
try: time.sleep(5)
self.rmq_connection = pika.BlockingConnection( for i in range(5):
pika.ConnectionParameters(self.get_parameter('server_hostname').get_parameter_value().string_value) try:
) self.rmq_connection = pika.BlockingConnection(
self.rmq_channel = self.rmq_connection.channel() pika.ConnectionParameters(host=self.get_parameter('server_hostname').get_parameter_value().string_value)
self.rmq_channel.exchange_declare( )
exchange="fmi_digital_twin", self.rmq_channel = self.rmq_connection.channel()
exchange_type='direct') self.rmq_channel.exchange_declare(
exchange="fmi_digital_twin",
result = self.rmq_channel.queue_declare('', exclusive=True) exchange_type='direct')
queue_name = result.method.queue
self.rmq_channel.queue_bind( result = self.rmq_channel.queue_declare('', exclusive=True)
exchange="fmi_digital_twin", queue_name = result.method.queue
queue=queue_name, self.rmq_channel.queue_bind(
routing_key="desktoprobotti.from_cosim") exchange="fmi_digital_twin",
queue=queue_name,
self.rmq_channel.basic_consume( routing_key="desktoprobotti.from_cosim")
queue=queue_name,
on_message_callback=self.on_msg_received, self.rmq_channel.basic_consume(queue=queue_name, on_message_callback=self.on_msg_received, auto_ack=True)
auto_ack=True)
except Exception as err:
except Exception as err: if i == 0:
self.get_logger().info("RabbitMQ Initialization failed. Is rabbitmq running?") self.get_logger().info("RabbitMQ Initialization failed. Is rabbitmq running?")
self.get_logger().info(err) 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: else:
self.get_logger().info("RabbitMQ Initialization Complete!") self.get_logger().info("Exiting")
self.rmq_channel.start_consuming() self.exit()
def init_rabbitmq(self): def init_rabbitmq(self):
consumer_thread = threading.Thread(target=self.start_consumer) 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