listener app never receives request respone
tekumara opened this issue · 8 comments
❯ python3 listener_app.py
======================================================================================
Panini service connected to NATS..
id: 68
name: listener_app__non_docker_env_597593__302149
NATS brokers:
* nats://127.0.0.1:4222
JetStream enabled: False
======================================================================================
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
panini==0.8.2
nats-py==2.2.0
nats-python==0.8.0
👋 Hello @tekumara ,
Thank you for bringing this to our attention. From the logs and code snippets you've provided, it looks like your listener_app
is connected to NATS in core mode (JetStream enabled: False
). This means it's using the traditional NATS approach for handling messages.
However, if you intend to use JetStream capabilities, the approach required for message handling is different than core NATS.
To use JetStream with Panini, you need to:
- Enable JetStream (
enable_js=True
). - Properly configure your streams and consumers, as demonstrated in the JetStream publisher microservice example from the documentation: https://panini.technology/JetStream.html .
If you have further questions or face any issues, please don't hesitate to ask. We're here to help!
Thanks @artas728 sorry I didn't describe the issue well. I'm following the README and expecting to see multiple request has been processed
log lines from the listener_app but I don't see any.
As per the README I'm expecting:
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
request {'data': 'request1234567890'} from some.subject.for.request has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
request {'data': 'request1234567890'} from some.subject.for.request has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
request {'data': 'request1234567890'} from some.subject.for.request has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
request {'data': 'request1234567890'} from some.subject.for.request has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
request {'data': 'request1234567890'} from some.subject.for.request has been processed
event {'data': 'event1234567890'} from some.subject.for.stream has been processed
request {'data': 'request1234567890'} from some.subject.for.request has been processed
Hello @tekumara,
Thank you for clarifying the issue. It seems like there might be a step missing in your setup. To see the expected 'request has been processed' log lines, you also need to run sender_app.py
along with listener_app.py
, as outlined in the README. The sender_app.py
will act as another microservice that sends the requests which listener_app
is supposed to receive and process.
Here is a brief step to follow:
- Run
listener_app.py
. - In a separate terminal instance, run
sender_app.py
.
Executing both will allow the interaction between the two, enabling listener_app.py
to receive and process the requests as you expect.
Please try running both applications as mentioned above and let us know if you encounter any further issues or if there is anything more we can assist you with!
So I am running the sending app at the same time in a separate terminal:
❯ python -m src.demo.sender_app
======================================================================================
Panini service connected to NATS..
id: 160
name: sender_app__non_docker_env_172165__573154
NATS brokers:
* nats://127.0.0.1:4222
JetStream enabled: False
======================================================================================
@tekumara, thank you for sharing the sender app logs. To clarify, when you're running sender_app
in the other terminal, are you saying that listener_app
is not receiving the expected request messages, as outlined in the README? Please confirm.
Yep that's right. I only get the output shown above from listener_app
.
Tthere is a minor mistake in the code from README.md. Below the same code but fixed.
Python 3.10
panini==0.8.2
nats-py==2.2.0
nats-python==0.8.0
listener app:
from panini import app as panini_app
app = panini_app.App(
service_name='listener_app',
host='127.0.0.1',
port=4222,
)
@app.listen("some.subject.for.request")
async def request_listener(msg):
""" request endpoint """
print(f"request {msg.data} from {msg.subject} has been processed")
return {"success": True, "message": "request has been processed"}
@app.listen("some.subject.for.stream")
async def stream_listener(msg):
""" stream endpoint """
print(f"event {msg.data} from {msg.subject} has been processed")
if __name__ == "__main__":
app.start()
sender app:
from panini import app as panini_app
app = panini_app.App(
service_name='sender_app',
host='127.0.0.1',
port=4222,
)
@app.task(interval=1)
async def request_periodically():
message = {"data": "request1234567890"}
response = await app.request(
subject="some.subject.for.request",
message=message,
)
print(response)
@app.task(interval=1)
async def publish_periodically():
message = {"data": "event1234567890"}
await app.publish(
subject="some.subject.for.stream",
message=message,
)
if __name__ == "__main__":
app.start()
Let me know if it works for you