Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got timed out with the given example #3

Open
WI-KIWI opened this issue Apr 4, 2023 · 0 comments
Open

Got timed out with the given example #3

WI-KIWI opened this issue Apr 4, 2023 · 0 comments

Comments

@WI-KIWI
Copy link

WI-KIWI commented Apr 4, 2023

Hi @CaioFilus ,
tried to bring the moleculer-client example work with this ServiceBroker
Following the example I got

In [1]: from moleculer_client import MoleculerClient
In [4]: moleculer = MoleculerClient(node_id='python-node', moleculer_nodeID="master", url='nats://127.0.0.1:4222')

In [5]: print(moleculer.discover())
---------------------------------------------------------------------------
timeout                                   Traceback (most recent call last)
<ipython-input-5-ea42592b8850> in <module>
----> 1 print(moleculer.discover())

/opt/miniconda3/envs/moleculerPy/lib/python3.6/site-packages/moleculer_client/moleculer_client.py in discover(self, broadcast)
     81         else:
     82             self.nc.publish(MoleculerCommands.DISCOVER.format(self.node), payload=json.dumps(body).encode())
---> 83         self.nc.wait(count=1)
     84         return result['payload']
     85

/opt/miniconda3/envs/moleculerPy/lib/python3.6/site-packages/pynats/client.py in wait(self, count)
    217         total = 0
    218         while True:
--> 219             command, result = self._recv(MSG_RE, PING_RE, OK_RE)
    220             if command is MSG_RE:
    221                 self._handle_message(result)

/opt/miniconda3/envs/moleculerPy/lib/python3.6/site-packages/pynats/client.py in _recv(self, *commands)
    259
    260     def _recv(self, *commands: Pattern[bytes]) -> Tuple[Pattern[bytes], Match[bytes]]:
--> 261         line = self._readline()
    262
    263         command = self._get_command(line)

/opt/miniconda3/envs/moleculerPy/lib/python3.6/site-packages/pynats/client.py in _readline(self, size)
    275
    276         while True:
--> 277             line = self._socket_file.readline()
    278             if not line:
    279                 raise NATSReadSocketError()

/opt/miniconda3/envs/moleculerPy/lib/python3.6/socket.py in readinto(self, b)
    584         while True:
    585             try:
--> 586                 return self._sock.recv_into(b)
    587             except timeout:
    588                 self._timeout_occurred = True

timeout: timed out

It seems the self.nc.wait(count=1) causes this error.

Meanwhile, using nats-python==0.7.0 to interact with the nats broker works well

In [6]: from pynats import NATSClient
   ...:
   ...: with NATSClient(url='nats://127.0.0.1:4222', socket_timeout=5) as client:
   ...:     # Connect
   ...:     client.connect()
   ...:
   ...:     # Subscribe
   ...:     def callback(msg):
   ...:         print(f"Received a message with subject {msg.subject}: {msg}")
   ...:
   ...:     client.subscribe(subject="MOL.DISCOVER.master", callback=callback)
   ...:
   ...:     # Publish a message
   ...:     client.publish(subject="MOL.DISCOVER.master", payload=b"test-payload")
   ...:
   ...:     # wait for 1 message
   ...:     client.wait(count=1)
   ...:
Received a message with subject MOL.DISCOVER.master: NATSMessage(sid=0, subject='MOL.DISCOVER.master', reply='', payload=b'test-payload')

Here the last line client.wait(count=1) does not cause this error.
Thanks for helping me address this error.

Environment

  • Python 3.6.13
  • moleculer-client 0.1.6
  • nats-python 0.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant