Comments (8)
👋 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!
from panini.
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.
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!
from panini.
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.
@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.
Yep that's right. I only get the output shown above from listener_app
.
from panini.
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.
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)
- Add arg "start_in" for a task and an interval task HOT 1
- If adding a middleware in tests (ErrorMiddleware for ex.) - diff datatypes tests failing HOT 1
- ValueError: Expected object or value - ujson does not support NaN
- Type for 'async def subscribe_new_subject()' throw the warning HOT 1
- DebugMiddleware feature
- README.md for utils not correct HOT 1
- Middlewares do not allow to use sync functions HOT 1
- Add possibility not to use asyncio.iscoroutinefunction in middlewares, but still support sync def HOT 1
- If nats doen't answer - the panini becomes idle HOT 1
- Async Event Loop
- How to catch Validator error HOT 7
- Exception DataTypeError happens but not catch HOT 2
- Custom Logger without files on a file system HOT 2
- DataTypeError raised when listener's return type is not JSON HOT 6
- TestClient.request() method does not have a data_type argument like the real client HOT 3
- Website returning 502 Bad Gateway HOT 1
- RuntimeError with aiohttp HOT 2
- AttributeError: 'NATSClient' object has no attribute '_js' HOT 1
- Move to nats-py 2.6.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from panini.