-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Eray Ates <[email protected]>
- Loading branch information
Showing
3 changed files
with
49 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package consumer | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/worldline-go/wkafka" | ||
) | ||
|
||
func ProcessSingleByte(ctx context.Context, raw []byte) error { | ||
var msg DataSingle | ||
if err := json.Unmarshal(raw, &msg); err != nil { | ||
return err | ||
Check failure on line 15 in example/consumer/byte.go GitHub Actions / sonarcloud
|
||
} | ||
|
||
return ProcessSingle(ctx, msg) | ||
} | ||
|
||
func RunExampleSingleByte(ctx context.Context, _ *sync.WaitGroup) error { | ||
client, err := wkafka.New( | ||
ctx, kafkaConfigSingle, | ||
wkafka.WithConsumer(consumeConfigSingle), | ||
wkafka.WithClientInfo("testapp", "v0.1.0"), | ||
) | ||
if err != nil { | ||
return err | ||
Check failure on line 28 in example/consumer/byte.go GitHub Actions / sonarcloud
Check failure on line 28 in example/consumer/byte.go GitHub Actions / sonarcloud
|
||
} | ||
|
||
defer client.Close() | ||
|
||
if err := client.Consume(ctx, wkafka.WithCallback(ProcessSingleByte)); err != nil { | ||
return fmt.Errorf("consume: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters