Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADDED, BREAKING] Services: queue group now configurable and can be disabled #800

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions examples/micro-arithmetics.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,6 @@ int main(int argc, char **argv)
microGroup *g = NULL;
char errorbuf[1024];

microServiceConfig cfg = {
.Description = "Arithmetic operations - NATS microservice example in C",
.Name = "c-arithmetics",
.Version = "1.0.0",
};
microEndpointConfig add_cfg = {
.Name = "add",
.Handler = handle_add,
};
microEndpointConfig divide_cfg = {
.Name = "divide",
.Handler = handle_divide,
};
microEndpointConfig multiply_cfg = {
.Name = "multiply",
.Handler = handle_multiply,
};

// Connect to NATS server
opts = parseArgs(argc, argv, "");
s = natsConnection_Connect(&conn, opts);
Expand All @@ -118,17 +100,34 @@ int main(int argc, char **argv)
}

// Create the Microservice that listens on nc.
microServiceConfig cfg = {
.Description = "Arithmetic operations - NATS microservice example in C",
.Name = "c-arithmetics",
.Version = "1.0.0",
};
err = micro_AddService(&m, conn, &cfg);

// Add the endpoints for the functions.
if (err == NULL)
microService_AddGroup(&g, m, "op");
{
microGroupConfig groupConfig = { .Prefix = "op" };
err = microService_AddGroup(&g, m, &groupConfig);
}
if (err == NULL)
err = microGroup_AddEndpoint(g, &add_cfg);
{
microEndpointConfig addConfig = { .Name = "add", .Handler = handle_add };
err = microGroup_AddEndpoint(g, &addConfig);
}
if (err == NULL)
err = microGroup_AddEndpoint(g, &multiply_cfg);
{
microEndpointConfig multiplyConfig = { .Name = "multiply", .Handler = handle_multiply };
err = microGroup_AddEndpoint(g, &multiplyConfig);
}
if (err == NULL)
err = microGroup_AddEndpoint(g, &divide_cfg);
{
microEndpointConfig divideConfig = { .Name = "divide", .Handler = handle_divide };
err = microGroup_AddEndpoint(g, &divideConfig);
}

// Run the service, until stopped.
if (err == NULL)
Expand Down
45 changes: 22 additions & 23 deletions examples/micro-func.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,6 @@ int main(int argc, char **argv)
microGroup *g = NULL;
char errorbuf[1024];

microServiceConfig cfg = {
.Description = "Functions - NATS microservice example in C",
.Name = "c-functions",
.Version = "1.0.0",
};
microEndpointConfig factorial_cfg = {
.Name = "factorial",
.Handler = handle_factorial,
};
microEndpointConfig fibonacci_cfg = {
.Name = "fibonacci",
.Handler = handle_fibonacci,
};
microEndpointConfig power2_cfg = {
.Name = "power2",
.Handler = handle_power2,
};

// Connect to NATS server
opts = parseArgs(argc, argv, "");
s = natsConnection_Connect(&conn, opts);
Expand All @@ -200,17 +182,34 @@ int main(int argc, char **argv)
}

// Create the Microservice that listens on nc.
err = micro_AddService(&m, conn, &cfg);
microServiceConfig serviceConfig = {
.Description = "Functions - NATS microservice example in C",
.Name = "c-functions",
.Version = "1.0.0",
};
err = micro_AddService(&m, conn, &serviceConfig);

// Add the endpoints for the functions.
if (err == NULL)
err = microService_AddGroup(&g, m, "f");
{
microGroupConfig groupConfig = { .Prefix = "f" };
err = microService_AddGroup(&g, m, &groupConfig);
}
if (err == NULL)
err = microGroup_AddEndpoint(g, &factorial_cfg);
{
microEndpointConfig factorialConfig = { .Name = "factorial", .Handler = handle_factorial };
err = microGroup_AddEndpoint(g, &factorialConfig);
}
if (err == NULL)
err = microGroup_AddEndpoint(g, &fibonacci_cfg);
{
microEndpointConfig fibonacciConfig = { .Name = "fibonacci", .Handler = handle_fibonacci };
err = microGroup_AddEndpoint(g, &fibonacciConfig);
}
if (err == NULL)
err = microGroup_AddEndpoint(g, &power2_cfg);
{
microEndpointConfig power2Config = { .Name = "power2", .Handler = handle_power2 };
err = microGroup_AddEndpoint(g, &power2Config);
}

// Run the service, until stopped.
if (err == NULL)
Expand Down
Loading