I have a fundamental problem in a docker container where when I try to start create and start two images where the second image (python and some scripts) is dependent on the first image.
This causes the second image to error out and stop. How can I adopt my python script to consume on the client, to wait for the client boot-up?
I don't think this problem is necessarily an Apache Pulsar problem, but here's some documentation for those interested
Consumer on Client
import pulsar
def initialize_consumer():
client = pulsar.Client('pulsar://localhost:6650')
consumer = client.subscribe('my-topic', 'my-subscription')
while True:
msg = consumer.receive()
try:
output_string = f"Received message {msg.data()} id={msg.message_id()}"
print(output_string)
with open('./output.txt', 'a') as f:
f.write(output_string + '\n')
# Acknowledge successful processing of the message
consumer.acknowledge(msg)
except:
# Message failed to be processed
consumer.negative_acknowledge(msg)
client.close()
This thread helped me since I had a Docker specific problem: Docker Compose wait for container X before starting Y
I essentially added a
healthcheckfor mystandaloneimage and then used therestart: on-failurefor myconprodimage and that seems to work.I'd still be interested in a python centered solution in the actualy consumer function above.
docker-compose.yamlfile ends up looking like this: