Cantil 1.0.0
Scalable publish-subscribe implementation.
Loading...
Searching...
No Matches
Cantil

License

Code/Documentation

Scalable publish-subscribe implementation.

Note, this project is under active development.

1. Features

  • User-defined message interface.
  • Red-black tree for the channels dictionary.
  • Memory pools for messages and queues.
  • Logger with trace levels and exceptions.
  • Common data structures: list, queue, dictionary.
  • Single-thread implementation.
  • Multi-thread implementation.

2. Portability

  • Platforms: ubuntu, macos, windows.
  • OSAL: operating system abstraction layer.
  • C99 support: gcc -std=c99 -pedantic ....

3. Build

Output file
libcantil.a
# default build
cd /path/to/cantil
make
# customized build
cd /my/empty/dir
/path/to/cantil/tools/configure.sh /path/to/config.yaml
make

4. Message broker

4.1. Define the message interface

static size_t size(void)
{
return sizeof(char[8]);
}
static void init(CnLoad* load, va_list vlist)
{
const char* format = va_arg(vlist, char*);
vsnprintf(load, 8, format, vlist);
}
static void deinit(CnLoad* load)
{
(void)load;
}
const struct CnLoadVt SAMPLE_LOAD_API[] = {
{.size = size, .ctor = init, .dtor = deinit}};
char CnLoad
Opaque data type that represents the message load.
Definition broker.h:80
Vtable for message construction.
Definition broker.h:87
size_t(* size)(void)
Callback for obtaining the size of the load.
Definition broker.h:98

4.2. Initialize the message broker

CnBroker* broker = broker_create(SAMPLE_LOAD_API);

4.3. Exchange messages

TEST(subscriber, should_receive_enqueued_message)
{
CnBroker* broker = broker_create(SAMPLE_LOAD_API);
CnChannel* ch = NULL;
subscribe(sber, "test");
publish(broker_search(broker, "test"), "%X", 0xF00D);
TEST_ASSERT_NULL(channel_gettopic(ch));
TEST_ASSERT_EQUAL_STRING("F00D", subscriber_await(sber, &ch));
TEST_ASSERT_EQUAL_STRING("test", channel_gettopic(ch));
broker_destroy(broker);
}
#define broker_search
Definition broker.h:56
#define subscribe
Definition broker.h:47
#define channel_gettopic
Definition broker.h:59
#define broker_destroy
Definition broker.h:53
#define publish
Definition broker.h:44
#define broker_create
Definition broker.h:50
#define subscriber_create
Definition broker.h:62
#define subscriber_await
Definition broker.h:68
struct CnSubscriber CnSubscriber
The subscriber.
Definition broker.h:142
struct CnBroker CnBroker
The message broker.
Definition broker.h:135
struct CnChannel CnChannel
The channel for messages.
Definition broker.h:153