new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Temporal · Develop · all subjects

nexus/service-contract

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Define Nexus Service contract with interface

A Nexus Service contract is defined as a C# interface decorated with `[NexusService]`. Each operation in the service is decorated with `[NexusOperation]` and defines input and output types. The interface includes an `EndpointName` static field referencing the endpoint name. Operations must have one input parameter and one output type. In polyglot environments, use Protobuf or JSON serialization; this example uses .NET classes serialized to JSON.

Nexus Service contract example

```csharp using NexusRpc; [NexusService] public interface IHelloService { static readonly string EndpointName = "nexus-simple-endpoint"; [NexusOperation] EchoOutput Echo(EchoInput input); [NexusOperation] HelloOutput SayHello(HelloInput input); public record EchoInput(string Message); public record EchoOutput(string Message); public record HelloInput(string Name, HelloLanguage Language); public record HelloOutput(string Message); public enum HelloLanguage { En, Fr, De, Es, Tr, } } ``` This example shows a Nexus Service interface with two operations: Echo and SayHello, each with their own input and output record types.

Nexus Service contract definition with Go structs

A Nexus Service contract is defined using Go constants and structs. The service name and operation name are string constants that uniquely identify the Service and Operation. Input types are defined as structs. For example, HelloServiceName is "my-hello-service", HelloOperationName is "say-hello", and HelloInput is a struct with a Name field of type string. The Operation output type matches the return type of the handler, in this case string.

Define Nexus Service contract with clear service and operation names

Define a clear contract for the Nexus Service with service names, operation names, and input/output types. The default data converter encodes payloads in the following order: Null, Byte array, Protobuf JSON, and JSON. In polyglot environments with multiple languages and SDKs, Protobuf and JSON are common choices for interoperability.

Define Nexus Service contract with @Service annotation

Define a Nexus Service interface annotated with @Service that describes the Service and Operation names along with input/output types. Each operation is annotated with @Operation. Input and output classes should use @JsonCreator and @JsonProperty annotations for JSON serialization. The default data converter encodes payloads in order: Null, Byte array, Protobuf JSON, and JSON.

Nexus Service interface definition with @Service and @Operation annotations

A Nexus Service is defined as a Java interface annotated with @Service. Each callable Nexus Operation is marked with the @Operation annotation. For example, a SayHelloNexusService interface declares a sayHello(String name) method returning String, which becomes a callable Nexus Operation. The @Service annotation establishes the contract between implementation and callers, providing type safety when invoking Operations and ensuring Operation Handlers fulfill the contract.

Example: Nexus Service interface definition

package helloworkflow; import io.nexusrpc.Operation; import io.nexusrpc.Service; @Service public interface SayHelloNexusService { @Operation String sayHello(String name); } This example defines a Nexus Service named SayHelloNexusService with one Operation that takes a String name and returns a String.

Define Nexus Service contract with dataclasses

Define a clear Nexus Service contract with input/output types using Python dataclasses. Example: ```python from dataclasses import dataclass import nexusrpc @dataclass class MyInput: name: str @dataclass class MyOutput: message: str @nexusrpc.service class MyNexusService: my_sync_operation: nexusrpc.Operation[MyInput, MyOutput] my_workflow_run_operation: nexusrpc.Operation[MyInput, MyOutput] ``` The default data converter encodes payloads in order: Null, Byte array, Protobuf JSON, and JSON. In polyglot environments, Protobuf and JSON are common choices.

Give your agent this brain