Skip to content

Instantly share code, notes, and snippets.

defp deps do
[
{:cowboy, [env: :prod, git: "https://github.com/ninenines/cowboy.git", tag: "2.2.0", override: true, manager: :make]},
{:ranch, [env: :prod, git: "https://github.com/ninenines/ranch.git", override: true, manager: :make]},
{:grpc, github: "tony612/grpc-elixir"},
]
end
def application do
[
mod: {ChattyApp, []},
applications: [:grpc]
]
end
syntax = "proto3";
package chatty;
service ChatService {
rpc SendMessage (SendMessageRequest) returns (SendMessageReply) {}
rpc FetchMessages (FetchMessagesRequest) returns (FetchMessagesReply) {}
}
message SendMessageRequest {
syntax = "proto3";
package chatty;
service ChatService {
rpc SendMessage (SendMessageRequest) returns (SendMessageReply) {}
rpc FetchMessages (FetchMessagesRequest) returns (FetchMessagesReply) {}
}
message SendMessageRequest {
syntax = "proto3";
package chatty;
service ChatService {
rpc SendMessage (SendMessageRequest) returns (SendMessageReply) {}
rpc FetchMessages (FetchMessagesRequest) returns (FetchMessagesReply) {}
}
message SendMessageRequest {
defmodule Chatty.ChatService.Server do
use GRPC.Server, service: Chatty.ChatService.Service
def send_message(request, _stream) do
Chatty.ChatState.put_message(request.chat_message)
Chatty.SendMessageReply.new()
end
def fetch_messages(_request, _stream) do
messages = Chatty.ChatState.get_messages()
defmodule Chatty.ChatState do
def start_link do
Agent.start_link(fn -> %{} end, name: __MODULE__)
end
def put_message(message) do
Agent.update(__MODULE__, &Map.put_new(&1, :os.system_time(:millisecond), message))
end
defmodule ChattyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec
children = [
supervisor(GRPC.Server.Supervisor, [{Chatty.ChatService.Server, 8080}]),
worker(Chatty.ChatState, []),
]
SELECT
*
FROM
users
WHERE
MATCH(surename) AGAINST ("Jones-Smith");
{
"name": "test",
"displayName": "test",
"description": "",
"version": "0.0.1",
"publisher": "aleksandra",
"engines": {
"vscode": "^1.30.0"
},
"categories": [