From e6676e431f1cb775142b7d0f0a00bb4ffd8d306e Mon Sep 17 00:00:00 2001 From: John Peters Date: Sun, 22 Oct 2023 23:56:06 -0500 Subject: [PATCH 1/2] "Added content from academy repo" --- README.md | 579 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 550 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 7029ee6..efd6ed9 100644 --- a/README.md +++ b/README.md @@ -80,26 +80,60 @@ catch (Exception ex) } ``` -We can also connect using a password: +A password-based connection would look like this (using the defualt root memphis login with Memphis open-source): -```c# +```csharp try { var options = MemphisClientFactory.GetDefaultOptions(); - options.Host = ""; - options.Username = ""; - options.Password = ""; // you will get it on client type user creation - options.AccountId = ; // You can find it on the profile page in the Memphis UI. This field should be set only on the cloud version of Memphis, otherwise it will be ignored + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); +} +catch (Exception ex) { + // handle exception +} +``` + +A JWT, token-based connection would look like this: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.ConnectionToken = "Token"; + var memphisClient = await MemphisClientFactory.CreateClient(options); +} +catch (Exception ex) { + // handle exception +} +``` + +Memphis needs to be configured to use token based connection. See the [docs](https://docs.memphis.dev/memphis/memphis-broker/concepts/security) for help doing this. + +A TLS based connection would look like this: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Tls = new TlsOptions("tlsFileName"); var memphisClient = await MemphisClientFactory.CreateClient(options); - ... } catch (Exception ex) { - Console.Error.WriteLine("Exception: " + ex.Message); - Console.Error.WriteLine(ex); + // handle exception } ``` +Memphis needs to configured for these use cases. To configure memphis to use TLS see the [docs](https://docs.memphis.dev/memphis/open-source-installation/kubernetes/production-best-practices#memphis-metadata-tls-connection-configuration). + + Once client created, the entire functionalities offered by Memphis are available. ### Disconnecting from Memphis @@ -145,6 +179,273 @@ catch (Exception ex) } ``` +The CreateStation method is used to create a station. Using the different options available, one can programically create many different types of stations. The Memphis UI can also be used to create stations to the same effect. + +A minimal example, using all default values would simply create a station with the given name: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var station = await memphisClient.CreateStation( + stationOptions: new StationOptions + { + Name = "MyNewStation" + } + ); +} +catch (Exception ex) +{ + // handle exception +} +``` + +To change what criteria the station uses to decide if a message should be retained in the station, change the retention type. The different types of retention are documented [here](https://github.com/memphisdev/memphis.net#retention-types) in the dotnet README. + +The unit of the rentention value will vary depending on the RetentionTypes. The [previous link](https://github.com/memphisdev/memphis.net#retention-types) also describes what units will be used. + +Here is an example of a station which will only hold up to 10 messages: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var station = await memphisClient.CreateStation( + stationOptions: new StationOptions + { + Name = "MyNewStation", + RetentionType = RetentionTypes.MESSAGES, + RetentionValue = 10 + } + ); +} +catch (Exception ex) +{ + // handle exception +} +``` + +Memphis stations can either store Messages on disk or in memory. A comparison of those types of storage can be found [here](https://docs.memphis.dev/memphis/memphis-broker/concepts/storage-and-redundancy#tier-1-local-storage). + +Here is an example of how to create a station that uses Memory as its storage type: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var station = await memphisClient.CreateStation( + stationOptions: new StationOptions + { + Name = "MyNewStation", + StorageType = StorageTypes.MEMORY + } + ); +} +catch (Exception ex) { + // handle exception +} +``` + +In order to make a station more redundant, replicas can be used. Read more about replicas [here](https://docs.memphis.dev/memphis/memphis-broker/concepts/storage-and-redundancy#replicas-mirroring). Note that replicas are only available in cluster mode. Cluster mode can be enabled in the [Helm settings](https://docs.memphis.dev/memphis/open-source-installation/kubernetes/1-installation#appendix-b-helm-deployment-options) when deploying Memphis with Kubernetes. + +Here is an example of creating a station with 3 replicas: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var station = await memphisClient.CreateStation( + stationOptions: new StationOptions + { + Name = "MyNewStation", + Replicas = 3 + } + ); +} +catch (Exception ex) +{ + // handle exception +} +``` + +Idempotency defines how Memphis will prevent duplicate messages from being stored or consumed. The duration of time the message ID's will be stored in the station can be set with IdempotencyWindowMs. If the environment Memphis is deployed in has unreliably connection and/or a lot of latency, increasing this value might be desiriable. The default duration of time is set to two minutes. Read more about idempotency [here](https://docs.memphis.dev/memphis/memphis-broker/concepts/idempotency). + +Here is an example of changing the idempotency window to 3 seconds: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var station = await memphisClient.CreateStation( + stationOptions: new StationOptions + { + Name = "MyNewStation", + IdempotenceWindowMs = 180_000 + } + ); +} +catch (Exception ex) +{ + // handle exception +} +``` + +The schema name is used to set a schema to be enforced by the station. The default value of "" ensures that no schema is enforced. Here is an example of changing the schema to a defined schema in schemaverse called "SensorLogs": + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var station = await memphisClient.CreateStation( + stationOptions: new StationOptions + { + Name = "MyNewStation", + SchemaName = "SensorLogs" + } + ); +} +catch (Exception ex) +{ + // handle exception +} +``` + +There are two options for sending messages to the [dead-letter station(DLS)](https://docs.memphis.dev/memphis/memphis-broker/concepts/dead-letter#terminology). These are SendPoisonMessageToDls and SendSchemaFailedMessageToDls. + +Here is an example of sending poison messages to the DLS but not messages which fail to conform to the given schema. + +```csharp + try + { + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var station = await memphisClient.CreateStation( + stationOptions: new StationOptions + { + Name = "MyNewStation", + SendPoisonMessageToDls = true, + SendSchemaFailedMessageToDls = false + } + ); + } + catch (Exception ex) + { + // handle exception + } +``` + +When either of the DLS flags are set to True, a station can also be set to handle these events. To set a station as the station to where schema failed or poison messages will be set to, use the DlsStation StationOptions: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var station = await memphisClient.CreateStation( + stationOptions: new StationOptions + { + Name = "MyNewStation", + SendPoisonMessageToDls = true, + SendSchemaFailedMessageToDls = false, + // DlsStation = "DeadLetterMessageStation" // Coming soon + } + ); +} +catch (Exception ex) +{ + // handle exception +} +``` + +When the retention value is met, Mempihs by default will delete old messages. If tiered storage is setup, Memphis can instead move messages to tier 2 storage. Read more about tiered storage [here](https://docs.memphis.dev/memphis/memphis-broker/concepts/storage-and-redundancy#storage-tiering). Enable this setting with the option provided: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var station = await memphisClient.CreateStation( + stationOptions: new StationOptions + { + Name = "MyNewStation", + TieredStorageEnabled = true + } + ); +} +catch (Exception ex) +{ + // handle exception +} +``` + +[Partitioning](https://docs.memphis.dev/memphis/memphis-broker/concepts/station#partitions) might be useful for a station. To have a station partitioned, simply change the partitions number: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var station = await memphisClient.CreateStation( + stationOptions: new StationOptions + { + Name = "MyNewStation", + PartitionsNumber = 3 + } + ); +} +catch (Exception ex) +{ + // handle exception +} +``` + + ### Retention types Memphis currently supports the following types of retention: @@ -281,36 +582,127 @@ await producer.ProduceAsync( Note: When producing to a station with more than one partition, the producer will produce messages in a Round Robin fashion between the different partitions. -### Async produce -For better performance. The client won't block requests while waiting for an acknowledgment. +The ProduceAsync method allows for the user to produce a message without discretely creating a producer. Because this creates a producer for every message, it is better to create a producer if many message need to be produced. + +For message data formats see [here](https://docs.memphis.dev/memphis/memphis-schemaverse/formats/produce-consume). + +Messages produced by ProduceAsync run asyncronously by default. By using the AsyncProduce Option this can be set to produce messages syncronously, waiting for an ack after each message is produced. By default, messages are sent while still waiting for the ack of previously sent messages. This reduces preceived network latency and will allow for producers to produce more messages however may incur a loss in reliability. + +Here is an example of a ProduceAsync method call that waits up to one minute for an acknowledgement from memphis and produces messages syncronously: ```csharp -await producer.ProduceAsync( - message: Encoding.UTF8.GetBytes(text), - headers: commonHeaders, - asyncProduceAck: true); +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + await memphisClient.ProduceAsync( + options: new MemphisProducerOptions + { + MaxAckTimeMs = 60_000, + StationName = "MyStation", + ProducerName = "MyProducer" + }, + message: Encoding.UTF8.GetBytes("MyMessage"), + asyncProduceAck: false + ); +} +catch (Exception ex) +{ + // handle exception +} ``` -### Sync produce -For better reliability. The client will block requests and will wait for an acknowledgment. +As discussed before in the station section, idempotency is an important feature of memphis. To achieve idempotency, an id must be assigned to messages that are being produced. Use the messageId parameter for this purpose. ```csharp -await producer.ProduceAsync( - message: Encoding.UTF8.GetBytes(text), - headers: commonHeaders, - asyncProduceAck: false); +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + await memphisClient.ProduceAsync( + options: new MemphisProducerOptions + { + MaxAckTimeMs = 60_000, + StationName = "MyStation", + ProducerName = "MyProducer" + }, + message: Encoding.UTF8.GetBytes("MyMessage"), + messageId: "UniqueMessageID" + ); +} +catch (Exception ex) +{ + // handle exception +} ``` -### Message ID +To add message headers to the message, use the headers parameter. Headers can help with observability when using certain 3rd party to help monitor the behavior of memphis. See [here](https://docs.memphis.dev/memphis/memphis-broker/comparisons/aws-sqs-vs-memphis#observability) for more details. -Stations are idempotent by default for 2 minutes (can be configured), Idempotence achieved by adding a message id +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); -```c# -await producer.ProduceAsync( - message: Encoding.UTF8.GetBytes(text), - headers:commonHeaders, - messageId:"id" // defaults to null -); + var headers = new NameValueCollection + { + { "trace_header", "track_me_123" } + }; + + await memphisClient.ProduceAsync( + options: new MemphisProducerOptions + { + MaxAckTimeMs = 60_000, + StationName = "MyStation", + ProducerName = "MyProducer" + }, + message: Encoding.UTF8.GetBytes("MyMessage"), + headers: headers + ); +} +catch (Exception ex) +{ + // handle exception +} +``` + +Lastly, memphis can produce to a specific partition in a station. To do so, use the partitionKey parameter: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + await memphisClient.ProduceAsync( + options: new MemphisProducerOptions + { + MaxAckTimeMs = 60_000, + StationName = "MyStation", + ProducerName = "MyProducer" + }, + message: Encoding.UTF8.GetBytes("MyMessage") + partitionKey: "Partition3" + ); +} +catch (Exception ex) +{ + // handle exception +} ``` ### Produce using partition key @@ -372,6 +764,135 @@ catch (Exception ex) Note: When consuming from a station with more than one partition, the consumer will consume messages in Round Robin fashion from the different partitions. +Use the Memphis CreateConsumer method to create a Consumer. It offeres some extra options that may be useful. + +Here is an example on how to create a consumer with all of the default options: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var consumer = await memphisClient.CreateConsumer(new MemphisConsumerOptions + { + StationName = "MyStation", + ConsumerName = "MyConsumer" + }); +} +catch (Exception ex) +{ + // handle exception +}handle exception +} +``` + +To create a consumer in a consumer group, add the ConsumerGroup MemphisConsumerOptions: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; +var memphisClient = await MemphisClientFactory.CreateClient(options); + + var consumer = await memphisClient.CreateConsumer(new MemphisConsumerOptions + { + StationName = "MyStation", + ConsumerName = "MyConsumer", + ConsumerGroup = "MyConsumerGroup1" + }); +} +catch (Exception ex) +{ + // handle exception +} +``` + +When using Consumer.consume, the consumer will continue to consume in an infinite loop. To change the rate at which the consumer polls, change the PullIntervalMs parameter: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var consumer = await memphisClient.CreateConsumer(new MemphisConsumerOptions + { + StationName = "MyStation", + ConsumerName = "MyConsumer", + PullIntervalMs = 2_000 + }); +} +catch (Exception ex) +{ + // handle exception +} +``` + +Every time the consumer polls, the consumer will try to take BatchSize number of elements from the station. However, sometimes there are not enough messages in the station for the consumer to consume a full batch. In this case, the consumer will continue to wait until either BatchSize messages are gathered or the time in milliseconds specified by BatchMaxTimeToWaitMs is reached. + +Here is an example of a consumer that will try to poll 100 messages every 10 seconds while waiting up to 15 seconds for all messages to reach the consumer. + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; +var memphisClient = await MemphisClientFactory.CreateClient(options); + + var consumer = await memphisClient.CreateConsumer(new MemphisConsumerOptions + { + StationName = "MyStation", + ConsumerName = "MyConsumer", + PullIntervalMs = 10_000, + BatchSize = 100, + BatchMaxTimeToWaitMs = 15_000 + }); +} +catch (Exception ex) +{ + // handle exception +} +``` + +The MaxMsgDeliveries parameter allows the user how many messages the consumer is able to consume before consuming more. + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "localhost"; + options.Username = "root"; + options.Password = "memphis"; + var memphisClient = await MemphisClientFactory.CreateClient(options); + + var consumer = await memphisClient.CreateConsumer(new MemphisConsumerOptions + { + StationName = "MyStation", + ConsumerName = "MyConsumer", + PullIntervalMs = 10_000, + BatchSize = 100, + BatchMaxTimeToWaitMs = 15_000, + MaxMsgDeliveries = 100 + }); +} +catch (Exception ex) +{ + // handle exception +} +``` + ### Creating message handler for consuming a message To configure message handler, use the `MessageReceived` event: From c3125b7f0a97d1fd7f79d0e25cedd8f3ec928ebc Mon Sep 17 00:00:00 2001 From: John Peters Date: Mon, 23 Oct 2023 23:28:36 -0500 Subject: [PATCH 2/2] "Synced with master. Added the changes that I made in the python repo to this one as well" --- README.md | 97 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 4eb8aa6..37822bc 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ using Memphis.Client; ### Connecting to Memphis +The createClient method in the Memphis class allows for the connection to Memphis. Connecting to Memphis (cloud or open-source) will be needed in order to use any of the other functionality of the Memphis class. Upon connection, all of Memphis' features are available. + First, we need to create or use default `ClientOptions` and then connect to Memphis by using `MemphisClientFactory.CreateClient(ClientOptions opts)`. ```c# @@ -80,7 +82,24 @@ catch (Exception ex) { } ``` -A JWT, token-based connection would look like this: +If you wanted to connect to Memphis cloud instead, simply add your account ID and change the host. The host and account_id can be found on the Overview page in the Memphis cloud UI under your name at the top. Here is an example to connecting to a cloud broker that is located in US East: + +```csharp +try +{ + var options = MemphisClientFactory.GetDefaultOptions(); + options.Host = "aws-us-east-1.cloud.memphis.dev"; + options.Username = "my_client_username"; + options.Password = "my_client_password"; + options.AccountId = 123456789; + var memphisClient = await MemphisClientFactory.CreateClient(options); +} +catch (Exception ex) { + // handle exception +} +``` + +It is possible to use a token-based connection to memphis as well, where multiple users can share the same token to connect to memphis. Here is an example of using memphis.connect with a token: ```csharp try @@ -96,6 +115,8 @@ catch (Exception ex) { } ``` +The token will be presented when creating new users. + Memphis needs to be configured to use token based connection. See the [docs](https://docs.memphis.dev/memphis/memphis-broker/concepts/security) for help doing this. A TLS based connection would look like this: @@ -117,9 +138,6 @@ catch (Exception ex) Memphis needs to configured for these use cases. To configure memphis to use TLS see the [docs](https://docs.memphis.dev/memphis/open-source-installation/kubernetes/production-best-practices#memphis-metadata-tls-connection-configuration). - -Once client created, the entire functionalities offered by Memphis are available. - ### Disconnecting from Memphis To disconnect from Memphis, call `Dispose()` on the `MemphisClient`. @@ -129,6 +147,11 @@ await memphisClient.Dispose() ``` ### Creating a Station +Stations are distributed units that store messages. Producers add messages to stations and Consumers take messages from them. Each station stores messages until their retention policy causes them to either delete the messages or move them to [remote storage](https://docs.memphis.dev/memphis/integrations-center/storage/s3-compatible). + +**A station will be automatically created for the user when a consumer or producer is used if no stations with the given station name exist.**

+_If the station trying to be created exists when this function is called, nothing will change with the exisitng station_ + ```c# try { @@ -432,56 +455,57 @@ catch (Exception ex) ### Retention types -Memphis currently supports the following types of retention: +Retention types define the methodology behind how a station behaves with its messages. Memphis currently supports the following retention types: ```c# RetentionTypes.MAX_MESSAGE_AGE_SECONDS ``` -The above means that every message persists for the value set in the retention value field (in seconds). +When the retention type is set to MAX_MESSAGE_AGE_SECONDS, messages will persist in the station for the number of seconds specified in the retention_value. ```c# RetentionTypes.MESSAGES ``` -The above means that after the maximum number of saved messages (set in retention value) has been reached, the oldest messages will be deleted. +When the retention type is set to MESSAGES, the station will only hold up to retention_value messages. The station will delete the oldest messsages to maintain a retention_value number of messages. ```c# RetentionTypes.BYTES ``` -The above means that after maximum number of saved bytes (set in retention value) has been reached, the oldest messages will be deleted. +When the retention type is set to BYTES, the station will only hold up to retention_value BYTES. The oldest messages will be deleted in order to maintain at maximum retention_vlaue BYTES in the station. ```c# RetentionTypes.ACK_BASED ``` -The above means that after a message is getting acked by all interested consumer groups it will be deleted from the Station. This retention type is for cloud users only. - +When the retention type is set to ACK_BASED, messages in the station will be deleted after they are acked by all subscribed consumer groups. ### Retention Values -The `retention values` are directly related to the `retention types` mentioned above,
where the values vary according to the type of retention chosen. - -All retention values are of type `int` but with different representations as follows: - -`RetentionTypes.MAX_MESSAGE_AGE_SECONDS` is represented **in seconds**, `RetentionTypes.MESSAGES` in a **number of messages**, `RetentionTypes.BYTES` in a **number of bytes**, and finally `RetentionTypes.ACK_BASED` is not using the retention value. +The unit of the `retention_value` changes depending on the `retention_type` specified. -After these limits are reached oldest messages will be deleted. +All retention values are of type `int`. The following units are used based on the respective retention type: +`RetentionTypes.MAX_MESSAGE_AGE_SECONDS` is represented **in seconds**,
+`RetentionTypes.MESSAGES` is a **number of messages**,
+`RetentionTypes.BYTES` is a **number of bytes**,
+With `RetentionTypes.ACK_BASED` the `RetentionType` is ignored. ### Storage Types + Memphis currently supports the following types of messages storage: ```c# StorageTypes.DISK ``` -The above means that messages persist on disk. +When storage is set to DISK, messages are stored on disk. ```c# StorageTypes.MEMORY ``` -The above means that messages persist in the main memory. +When storage is set to MEMORY, messages are stored in the system memory. ### Destroying a Station Destroying a station will remove all its resources (including producers and consumers). + ```c# station.DestroyAsync() ``` @@ -513,16 +537,18 @@ await client.DetachSchema(stationName: station.Name); ### Produce and Consume messages -The most common client operations are `produce` to send messages and `consume` to +The most common client operations are using `produce` to send messages and `consume` to receive messages. -Messages are published to a station and consumed from it by creating a consumer. -Consumers are pull-based and consume all the messages in a station unless you are using a consumers group, in this case, messages are spread across all members in this group. +Messages are published to a station with a Producer and consumed from it by a Consumer. -Memphis messages are payload agnostic. Payloads are `byte[]`. +Consumers are poll based and consume all the messages in a station. Consumers can also be grouped into consumer groups. When consuming with a consumer group, all consumers in the group will receive each message. -In order to stop getting messages, you have to call `consumer.Dispose()`. Destroy will terminate regardless -of whether there are messages in flight for the client. +Memphis messages are payload agnostic. Payloads are always `byte[]`s. + +In order to stop getting messages, you have to call `consumer.Dispose()`. Destroy will terminate the consumer even if messages are currently being sent to the consumer. + +If a station is created with more than one partition, producing to and consuming from the station will happen in a round robin fashion. ### Creating a Producer @@ -561,8 +587,6 @@ await producer.ProduceAsync( headers:commonHeaders ); ``` - - Note: When producing to a station with more than one partition, the producer will produce messages in a Round Robin fashion between the different partitions. @@ -661,7 +685,7 @@ catch (Exception ex) } ``` -Lastly, memphis can produce to a specific partition in a station. To do so, use the partitionKey parameter: +Memphis can produce to a specific partition in a station. To do so, use the partitionKey parameter: ```csharp try @@ -689,17 +713,6 @@ catch (Exception ex) } ``` -### Produce using partition key -The partition key will be used to produce messages to a spacific partition. - -```csharp -await producer.ProduceAsync( - message: Encoding.UTF8.GetBytes(text), - headers:commonHeaders, - partitionKey:"" -); -``` - ### Produce using partition number The partition number will be used to produce messages to a spacific partition. @@ -748,7 +761,7 @@ catch (Exception ex) Note: When consuming from a station with more than one partition, the consumer will consume messages in Round Robin fashion from the different partitions. -Use the Memphis CreateConsumer method to create a Consumer. It offeres some extra options that may be useful. +Use the Memphis CreateConsumer method to create a Consumer. Consumers are used to pull messages from stations. Here is an example on how to create a consumer with all of the default options: @@ -824,7 +837,7 @@ catch (Exception ex) Every time the consumer polls, the consumer will try to take BatchSize number of elements from the station. However, sometimes there are not enough messages in the station for the consumer to consume a full batch. In this case, the consumer will continue to wait until either BatchSize messages are gathered or the time in milliseconds specified by BatchMaxTimeToWaitMs is reached. -Here is an example of a consumer that will try to poll 100 messages every 10 seconds while waiting up to 15 seconds for all messages to reach the consumer. +Here is an example of a consumer that will try to pull 100 messages from a station every 10 seconds while waiting up to 15 seconds for all messages to reach the consumer. ```csharp try @@ -939,10 +952,12 @@ consumer.MessageReceived += (sender, args) => }; ``` -if you have ingested data into station in one format, afterwards you apply a schema on the station, the consumer won't deserialize the previously ingested data. For example, you have ingested string into the station and attached a protobuf schema on the station. In this case, consumer won't deserialize the string. +There may be some instances where you apply a schema *after* a station has received some messages. In order to consume those messages get_data_deserialized may be used to consume the messages without trying to apply the schema to them. As an example, if you produced a string to a station and then attached a protobuf schema, using get_data_deserialized will not try to deserialize the string as a protobuf-formatted message. ### Fetch a single batch of messages +Using fetch_messages or fetch will allow the user to remove a specific number of messages from a given station. This behavior could be beneficial if the user does not want to have a consumer actively poll from a station indefinetly. + ```c# client.FetchMessages(new FetchMessageOptions {