<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          kaca消息發(fā)布/訂閱系統(tǒng)

          聯(lián)合創(chuàng)作 · 2023-10-01 03:46

          kaca 是用 golang 語言開發(fā)的基于 websocket 協(xié)議的消息發(fā)布/訂閱系統(tǒng)。

          服務(wù)器端代碼:

          package main
          
          import (
                  "github.com/scottkiss/kaca"
                 )
          
          func main() {
              //use true to set check origin
              kaca.ServeWs(":8080",true)
          }

          發(fā)布訂閱客戶端:

          package main
          
          import (
              "fmt"
              "github.com/scottkiss/kaca"
              "time"
             )
          
          func main() {
                    producer := kaca.NewClient(":8080", "ws")
                    consumer := kaca.NewClient(":8080", "ws")
                    consumer.Sub("say")
                    consumer.Sub("you")
                    consumer.ConsumeMessage(func(message string) {
                            fmt.Println("consume =>" + message)
                            })
                time.Sleep(time.Second * time.Duration(2))
                    producer.Pub("you", "world")
                    producer.Pub("say", "hello")
                    time.Sleep(time.Second * time.Duration(2))
          }

          廣播客戶端:

          package main
          
          import (
              "fmt"
              "github.com/scottkiss/kaca"
              "time"
             )
          
          func main() {
                    producer := kaca.NewClient(":8080", "ws")
                    consumer := kaca.NewClient(":8080", "ws")
                    c2 := kaca.NewClient(":8080", "ws")
                    c2.ConsumeMessage(func(message string) {
                            fmt.Println("c2 consume =>" + message)
                            })
                    consumer.Sub("say")
                    consumer.Sub("you")
                    consumer.ConsumeMessage(func(message string) {
                            fmt.Println("consume =>" + message)
                            })
                    time.Sleep(time.Second * time.Duration(2))
                    producer.Broadcast("broadcast...")
                    time.Sleep(time.Second * time.Duration(2))
          })
          }
          瀏覽 24
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产成人精品无码 | 免免费国产AAAAA片牛牛影视 | 日韩一级免费视频 | 手机操逼网站 | 看操逼逼 |