Giter Site home page Giter Site logo

Comments (8)

artas728 avatar artas728 commented on June 24, 2024

👋 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:

  1. Enable JetStream (enable_js=True).
  2. 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!

from panini.

tekumara avatar tekumara commented on June 24, 2024

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

from panini.

artas728 avatar artas728 commented on June 24, 2024

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:

  1. Run listener_app.py.
  2. 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!

from panini.

tekumara avatar tekumara commented on June 24, 2024

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
======================================================================================

from panini.

artas728 avatar artas728 commented on June 24, 2024

@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.

from panini.

tekumara avatar tekumara commented on June 24, 2024

Yep that's right. I only get the output shown above from listener_app.

from panini.

artas728 avatar artas728 commented on June 24, 2024

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

from panini.

tekumara avatar tekumara commented on June 24, 2024

Hi @artas728 I figured it out, using the original code from the README. I have to start the listener app first. If I start the sender app first I never see any requests. Thanks for all your help!

from panini.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.