Thank you very much :) for the awesome explanation! I am probably going for 
the second approach (more or less like a registry I think?).

I still have one question though, in the case of one `SocketAddress` having 
more than one topics with the same type, do you think it is appropriate to 
just add a `topic` field to the `subscribe` method and return the 
corresponding `Subscription`?

For future visitors looking to implement such RPC schemes without `ez-rpc`, 
I have done a little writeup here 
<https://corerc.io/blog/2018/08/31/first-cross-language-pub-sub-on-capn-proto/>.
 
Please feel free to point out my errors if you found one :)

Best,

Fan

On Friday, August 31, 2018 at 2:30:46 PM UTC+8, David Renshaw wrote:
>
>
> You could have something like this:
> ```
> interface RegistrationHandle {}
>
> interface PubSubMaster {
>      registerPublisher @0 (publisher :Publisher(AnyPointer), topic :Text) 
> -> (handle: RegistrationHandle)
>      # Registers a publisher on a topic. Dropping the returned handled 
> de-registers the publisher.
>
>      getPublishersForTopic @1 (topic :Text) -> (publishers 
> :List(Publisher(AnyPointer)))
>      # Gets all of the currently registered publishers for a topic.
> }
> ```
>
> Note, however, that in this setup all of the published messages end up 
> going through the PubSubMaster's vat. If your publishers live in different 
> vats from the PubSubMaster -- as is the case when they are in different 
> processes or on different machines -- then the PubSubMaster vat will proxy 
> all of the published messages.
>
> To avoid such proxying, you might instead consider something more like 
> this:
> ```
> struct SocketAddress {
>     # IP address and port ...
> }
>
> interface DirectPubSubMaster {
>      registerPublisher @0 (publisher :SocketAddress, topic :Text) -> 
> (handle: RegistrationHandle)
>      getPublishersForTopic @1 (topic :Text) -> (publishers 
> :List(SocketAddress))
> }
> ```
>
> In this case, subscribers connect directly to publishers. The downside is 
> that they need to manually handle the connection logic.
>
> My understanding is that "three way introductions" (see 
> https://capnproto.org/rpc.html#protocol-features ) will someday allow 
> such direct connections to be formed automatically, without us needing to 
> talk about addresses in our interface definitions.
>
> - David
>
> On Thu, Aug 30, 2018 at 7:22 PM Fan Jiang <[email protected] 
> <javascript:>> wrote:
>
>> Hi,
>>
>> I've been working on Pub/Sub-style communication on Cap'n Proto. 
>> Currently I have ported the Rust-based example 
>> <https://github.com/capnproto/capnproto-rust/tree/master/capnp-rpc/examples/pubsub>
>>   
>> to C++, and achieved cross-language Pub/Sub.
>> However, this demo implementation only allows for subscribing to a 
>> specific data type, not to a specific topic name.
>>
>> @0xce579c3e9bb684bd;
>>
>> interface Subscription {}
>>
>> interface Publisher(T) {
>>     # A source of messages of type T.
>>
>>     subscribe @0 (subscriber: Subscriber(T)) -> (subscription: 
>> Subscription);
>>     # Registers `subscriber` to receive published messages. Dropping the 
>> returned `subscription`
>>     # signals to the `Publisher` that the subscriber is no longer 
>> interested in receiving messages.
>> }
>>
>> interface Subscriber(T) {
>>     pushMessage @0 (message: T) -> ();
>>     # Sends a message from a publisher to the subscriber. To help with 
>> flow control, the subscriber should not
>>     # return from this method until it is ready to process the next 
>> message.
>> }
>>
>> Any idea on how to add the concept of "topic" in the "Cap'n Proto" style?
>>
>> Deeply thanks for your help,
>>
>> Fan Jiang
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Cap'n Proto" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> Visit this group at https://groups.google.com/group/capnproto.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to