3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ScalaでPusherクライアント作りました

Posted at

Pusherとは

WebSocketを使ってチャットアプリ等を実装するためのサービス。

Pusherを経由してWebhook, Rest APIを使うことでオンラインユーザへのメッセージの送信などが簡単にできます。

いろいろな言語でオフィシャルにクライアントライブラリが提供されていますが、Scalaはなかったので作ってみました。

使い方は簡単、

build.sbtに以下を追加。

build.sbt
libraryDependencies += "com.github.dtaniwaki" %% "akka-pusher" % "x.y.z"

application.confに以下を追加。

application.conf
pusher {
  appId=${?PUSHER_APP_ID}
  key=${?PUHSER_API_KEY}
  secret=${?PUSHER_API_SECRET}
}

importして実行。

import com.github.dtaniwaki.akka_pusher.PusherClient

val pusher = new PusherClient()
pusher.trigger("test_channel", "my_event", "hello world")
// Send the message to the connected users
pusher.shutdown()

試しに、Spray上にこのライブラリを使ったAPIサーバを実装してみました。

お試しあれ。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?