syntax = "proto3";

option go_package = "github.com/redhatinsights/yggdrasil/protocol";

package yggdrasil;

service Dispatcher {
    // Register is called by a worker to indicate it is ready and capable of
    // handling the specified type of work.
    rpc Register (RegistrationRequest) returns (RegistrationResponse) {}

    // Send is called by a worker to send data to the dispatcher.
    rpc Send (Data) returns (Receipt) {}
}

service Worker {
    // Send is called by the dispatcher to send data to a worker.
    rpc Send (Data) returns (Receipt) {}
}

// An Empty message.
message Empty {}

// A RegistrationRequest message contains information necessary for a client to
// request registration with the dispatcher for a specified work type.
message RegistrationRequest {
    // The type of work the worker is capable of handling.
    string handler = 1;

    // The PID of the worker.
    int64 pid = 2;

    // Whether or not the worker requires detached content processing.
    bool detached_content = 3;

    // A set of features a worker can announce during registration.
    map<string, string> features = 4;
}

// A RegistrationResponse message contains the result of a registration request.
message RegistrationResponse {
    // Whether or not the dispatcher accepted the registration request.
    bool registered = 1;

    // The address on which the worker can be dialed to assign work.
    string address = 2;
}

// A Data message contains data and metadata suitable to exchange data between
// the dispatcher and a worker.
message Data {
    // The MQTT message ID that generated this message.
    string message_id = 1;

    // Optional key-value pairs to be included in the data message.
    map<string, string> metadata = 2;

    // The data payload.
    bytes content = 3;

    // The MQTT message ID this message is in response to.
    string response_to = 4;

    // The destination of the message.
    string directive = 5;
}

// A Receipt message is sent as a successful response to a Send method.
message Receipt {}
