@@ -49,9 +49,10 @@ Implemented transports:
49494 . [ Async and Concurrency] ( #async-and-concurrency )
50505 . [ RPC and Distributed Computing] ( #rpc-and-distributed-computing )
51516 . [ Publisher / Subscriber Model] ( #publisher-subscriber-model )
52- 7 . [ ncurl Minimalist http Client] ( #ncurl-minimalist-http-client )
53- 8 . [ Building from source] ( #building-from-source )
54- 9 . [ Links] ( #links )
52+ 7 . [ Surveyor / Repondent Model] ( #surveyor-respondent-model )
53+ 8 . [ ncurl Minimalist http Client] ( #ncurl-minimalist-http-client )
54+ 9 . [ Building from source] ( #building-from-source )
55+ 10 . [ Links] ( #links )
5556
5657### Installation
5758
@@ -253,8 +254,8 @@ msg <- recv_aio(s2)
253254call_aio(msg )
254255msg
255256# > < recvAio >
256- # > - $raw for raw message
257257# > - $data for message data
258+ # > - $raw for raw message
258259msg $ data
259260# > a b
260261# > 1 1 2
@@ -325,10 +326,9 @@ call_aio(aio)
325326
326327aio
327328# > < recvAio >
328- # > - $raw for raw message
329329# > - $data for message data
330330str(aio $ data )
331- # > num [1:100000000] 0.837 1.301 2.225 1.43 -1.543 ...
331+ # > num [1:100000000] -2.12 -0.152 -0.485 1.971 0.061 ...
332332```
333333
334334In this example the calculation is returned, but other operations may
@@ -354,48 +354,100 @@ The log level can also be set externally in production environments via
354354an environment variable ` NANONEXT_LOG ` .
355355
356356``` r
357+ # set logging level to include information events ------------------------------
357358logging(level = " info" )
358- # > 2022-03-03 10:51:39 [ log level ] set to: info
359+ # > 2022-03-03 16:31:20 [ log level ] set to: info
359360
360361pub <- socket(" pub" , listen = " inproc://nanobroadcast" )
361- # > 2022-03-03 10:51:39 [ sock open ] id: 9 | protocol: pub
362- # > 2022-03-03 10:51:39 [ list start ] sock: 9 | url: inproc://nanobroadcast
362+ # > 2022-03-03 16:31:20 [ sock open ] id: 9 | protocol: pub
363+ # > 2022-03-03 16:31:20 [ list start ] sock: 9 | url: inproc://nanobroadcast
363364sub <- socket(" sub" , dial = " inproc://nanobroadcast" )
364- # > 2022-03-03 10:51:39 [ sock open ] id: 10 | protocol: sub
365- # > 2022-03-03 10:51:39 [ dial start ] sock: 10 | url: inproc://nanobroadcast
365+ # > 2022-03-03 16:31:20 [ sock open ] id: 10 | protocol: sub
366+ # > 2022-03-03 16:31:20 [ dial start ] sock: 10 | url: inproc://nanobroadcast
366367
368+ # subscribing to a specific topic 'examples' -----------------------------------
367369sub | > subscribe(topic = " examples" )
368- # > 2022-03-03 10:51:39 [ subscribe ] sock: 10 | topic: examples
370+ # > 2022-03-03 16:31:20 [ subscribe ] sock: 10 | topic: examples
369371pub | > send(c(" examples" , " this is an example" ), mode = " raw" , echo = FALSE )
370372sub | > recv(mode = " character" , keep.raw = FALSE )
371373# > [1] "examples" "this is an example"
372374
373375pub | > send(c(" other" , " this other topic will not be received" ), mode = " raw" , echo = FALSE )
374376sub | > recv(mode = " character" , keep.raw = FALSE )
375- # > 2022-03-03 10:51:39 [ 8 ] Try again
377+ # > 2022-03-03 16:31:20 [ 8 ] Try again
376378
377- # specify NULL to subscribe to ALL topics
379+ # specify NULL to subscribe to ALL topics --------------------------------------
378380sub | > subscribe(topic = NULL )
379- # > 2022-03-03 10:51:39 [ subscribe ] sock: 10 | topic: ALL
381+ # > 2022-03-03 16:31:20 [ subscribe ] sock: 10 | topic: ALL
380382pub | > send(c(" newTopic" , " this is a new topic" ), mode = " raw" , echo = FALSE )
381383sub | > recv(" character" , keep.raw = FALSE )
382384# > [1] "newTopic" "this is a new topic"
383385
384386sub | > unsubscribe(topic = NULL )
385- # > 2022-03-03 10:51:39 [ unsubscribe ] sock: 10 | topic: ALL
387+ # > 2022-03-03 16:31:20 [ unsubscribe ] sock: 10 | topic: ALL
386388pub | > send(c(" newTopic" , " this topic will now not be received" ), mode = " raw" , echo = FALSE )
387389sub | > recv(" character" , keep.raw = FALSE )
388- # > 2022-03-03 10:51:39 [ 8 ] Try again
390+ # > 2022-03-03 16:31:20 [ 8 ] Try again
389391
390- # however the topics explicitly subscribed to are still received
392+ # however the topics explicitly subscribed to are still received ---------------
391393pub | > send(c(" examples" , " this example will still be received" ), mode = " raw" , echo = FALSE )
392394sub | > recv(mode = " character" , keep.raw = FALSE )
393395# > [1] "examples" "this example will still be received"
394396
397+ # set logging level back to the default of errors only -------------------------
398+ logging(level = " error" )
399+ # > 2022-03-03 16:31:20 [ log level ] set to: error
400+
395401close(pub )
396- # > 2022-03-03 10:51:39 [ sock close ] id: 9 | protocol: pub
397402close(sub )
398- # > 2022-03-03 10:51:39 [ sock close ] id: 10 | protocol: sub
403+ ```
404+
405+ [ « Back to ToC] ( #table-of-contents )
406+
407+ ### Surveyor Respondent Model
408+
409+ This type of topology is useful for applications such as service
410+ discovery.
411+
412+ ``` r
413+ sur <- socket(" surveyor" , listen = " inproc://nanoservice" )
414+ res1 <- socket(" respondent" , dial = " inproc://nanoservice" )
415+ res2 <- socket(" respondent" , dial = " inproc://nanoservice" )
416+
417+ # sur sets a survey timeout, applying to this and subsequent surveys -----------
418+ sur | > survey_time(500 )
419+
420+ # sur sends a message and then requests 2 async receives -----------------------
421+ sur | > send(" service check" , echo = FALSE )
422+ aio1 <- sur | > recv_aio()
423+ aio2 <- sur | > recv_aio()
424+
425+ # res1 receives the message and replies using an aio send function -------------
426+ res1 | > recv(keep.raw = FALSE )
427+ # > [1] "service check"
428+ res1 | > send_aio(" res1" )
429+ # > < sendAio >
430+ # > - $result for send result
431+
432+ # res2 receives the message but fails to reply ---------------------------------
433+ res2 | > recv(keep.raw = FALSE )
434+ # > [1] "service check"
435+
436+ # checking the aio - only the first will have resolved -------------------------
437+ aio1 $ data
438+ # > [1] "res1"
439+ aio2 $ data
440+ # > < unresolved value >
441+
442+ # after the survey expires, the second resolves into a timeout error -----------
443+ Sys.sleep(0.5 )
444+ aio2 $ data
445+ # > 2022-03-03 16:31:21 [ 5 ] Timed out
446+ # > [1] 5
447+
448+ close(sur )
449+ close(res1 )
450+ close(res2 )
399451```
400452
401453[ « Back to ToC] ( #table-of-contents )
@@ -411,11 +463,11 @@ ncurl("http://httpbin.org/headers")
411463# > [1] 7b 0a 20 20 22 68 65 61 64 65 72 73 22 3a 20 7b 0a 20 20 20 20 22 48 6f 73
412464# > [26] 74 22 3a 20 22 68 74 74 70 62 69 6e 2e 6f 72 67 22 2c 20 0a 20 20 20 20 22
413465# > [51] 58 2d 41 6d 7a 6e 2d 54 72 61 63 65 2d 49 64 22 3a 20 22 52 6f 6f 74 3d 31
414- # > [76] 2d 36 32 32 30 39 64 62 62 2d 34 61 61 66 66 65 31 37 32 61 64 64 35 39 35
415- # > [101] 35 37 33 31 62 35 34 30 30 22 0a 20 20 7d 0a 7d 0a
466+ # > [76] 2d 36 32 32 30 65 64 35 39 2d 32 31 64 36 39 31 30 32 31 32 62 30 63 39 34
467+ # > [101] 64 30 65 61 36 32 63 31 30 22 0a 20 20 7d 0a 7d 0a
416468# >
417469# > $data
418- # > [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-62209dbb-4aaffe172add5955731b5400 \"\n }\n}\n"
470+ # > [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6220ed59-21d6910212b0c94d0ea62c10 \"\n }\n}\n"
419471```
420472
421473For advanced use, supports additional HTTP methods such as POST or PUT.
0 commit comments