Comments (15)
If you have a running server from this example:
https://github.com/paritytech/jsonrpc/blob/a95e135017c3a29fbda5dad88dc62f8797792443/pubsub/examples/pubsub.rs
You need to issue a standard RPC with {"id":1,"jsonrpc":"2.0","method":"subscribe_hello"}
and then you should start seeing subscriptions coming to your client.
The transport used in the example is TCP, so you can for instance use netcat
to connect to the server:
$ netcat localhost 3030 -
{"id":1,"jsonrpc":"2.0","method":"subscribe_hello"}
{"jsonrpc":"2.0","result":5,"id":1}
{"jsonrpc":"2.0","method":"hello","params":[10]}
{"jsonrpc":"2.0","method":"hello","params":[10]}
{"jsonrpc":"2.0","method":"hello","params":[10]}
from jsonrpc.
I'm running the example using macros at https://github.com/paritytech/jsonrpc/blob/a95e135017c3a29fbda5dad88dc62f8797792443/macros/examples/pubsub-macros.rs
But I get this:
$ netcat localhost 3030 -
{"id":1,"jsonrpc":"2.0","method":"hello_subscribe"}
{"jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found"},"id":1}
from jsonrpc.
I did get your example to work with the example not using macros. But using the macros would be sweet.
from jsonrpc.
Hmm, you're right. It turned out that the alias invocation in macros
was invalid (it was overriding the implementation with alias to non-existent method).
Please try with #121 or remove alias
in the example.
from jsonrpc.
That worked better! Thanks. Now I get:
$ netcat localhost 3030 -
{"id":1,"jsonrpc":"2.0","method":"hello_subscribe","params":[10]}
{"jsonrpc":"2.0","result":0,"id":1}
{"jsonrpc":"2.0","method":"hello","params":{"result":"Hello World!","subscription":0}}
{"jsonrpc":"2.0","method":"hello","params":{"result":"Hello World!","subscription":0}}
{"jsonrpc":"2.0","method":"hello","params":{"result":"Hello World!","subscription":0}}
....
Now I will just move on to try to get this running on the WebSocket server.
from jsonrpc.
You can have a look how we wrapped the ws::Sender
into mpsc::Sender
:
https://github.com/paritytech/parity/pull/5456/files#diff-047350db0c9925ab2d582dfcd955f0a4R173
I'm considering moving this into this crate though.
If you manage to get the example running feel free to contribue it to ws/examples
:)
from jsonrpc.
I got the server running. But when I try to communicate with in using a python websocket client I get this response:
{"jsonrpc":"2.0","error":{"code":-32090,"message":"Subscriptions are not available on this transport."},"id":1}
Is there anything I can do about that? Would the ws crate need some modifications or which part is it that stops subscriptions to work over ws?
from jsonrpc.
Could you post the example somewhere? For PubSub to work you need to ensure that MetadataExtractor
will create a Session
object (that definitely needs more detailed documentation).
from jsonrpc.
Ah. My bad. I removed the call to session_meta_extractor
. Now I'm trying to figure out how to make that work. Looking at the code you sent, but it uses rpc::PubSubSession
which is not part of this repository.
from jsonrpc.
It kind of escalates with the WsRpcExtractor
and the Sender
struct implementing Future
etc. There is hopefully a simpler way that I have not found yet.
from jsonrpc.
It's actually just a re-export of jsonrpc_pubsub::Session
. I'll prepare an example today for you :)
from jsonrpc.
Thank you. That would be awesome.
from jsonrpc.
Please have a look at #126. I've moved the implementation of mpsc::Sender
to this crate.
from jsonrpc.
@tomusdrw Thanks for the help! Got it working and also got an example based on macros working. Merging that PR would solve/close this issue.
from jsonrpc.
Awesome! Glad to hear that.
from jsonrpc.
Related Issues (20)
- Incompatible with async_trait?
- WS ERROR in frame.rs
- Request log HOT 1
- how to create new handler when new connection income HOT 1
- Example for Client Support not working HOT 2
- how can i define rpc trait in another mod? HOT 2
- did support config http path for rpc handler, like '/rpc/v0'
- how the jsonrpc params like in rpc trait
- skip params when it is `None`
- How to make bi-directional rpc?
- How to asynchronously process a request in the middleware?
- Expose the parts of jsonrpc_core_client necessary to create a custom transport HOT 2
- Implement the HTTP/2 protocol to increase the number of concurrent requests HOT 1
- Notify should allow Obj Params
- The tcp json server example not worked! HOT 3
- support jsonrpc batch
- Is the project still maintained? HOT 2
- Passing params as struct using derive-macro HOT 1
- Stdio client
- Is there an upgrade doc about how to upgrade from non async version to sync version
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 jsonrpc.