Skip to content

Documentation needed for MQTT.Server #6

@mynameisrufus

Description

@mynameisrufus

I'm having trouble running the server. I'm running mix test with the following test in it:

defmodule MyMqttServerTest do
  use ExUnit.Case
  alias MQTT.Client

  test "greets the world" do
    {:ok, connection, false} = MQTT.Client.connect(%{
        transport: {:tcp, %{host: "localhost", port: 1883}},
        client_id: UUID.uuid1()
    })

    topic = "/hello"
    message = "hello"

    {:ok, [{^topic, 0}]} = Client.subscribe(connection, [{topic, 0}])
    :ok = Client.publish(connection, topic, message)

    assert_receive {:mqtt_client, ^connection, {:publish, ^topic, ^message, _}}

    :ok = Client.disconnect(connection)
  end
end

Child process:

%{
  id: MyMqttServer,
  type: :worker,
  start: {MyMqttServer, :start_link, [[:hello]]}
}
defmodule MyMqttServer do
  use MQTT.Server

  def start_link(state) do
    GenServer.start_link(__MODULE__, state, name: __MODULE__)
  end

  def init(stack) do
    {:ok, stack}
  end

  def init(stack, _) do
    {:ok, stack}
  end
  
  def handle_subscribe(_topic, _qos, state) do
    IO.inspect("I never get output")
    {:ok, state}
  end
end

It seems to be running but I can't seem to override the fun? I'm still relatively new to this so apologies if this is a simple question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions