-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send advertised host and port in open (#40)
* Send Send advertised host and port in open https://github.com/rabbitmq/rabbitmq-server/pull/3060/files fix offest client side and test * Change error handling remove pre-declared option on the perf test, in the same way as Java client does. It checks the PreconditionFailed condition. cc @gerhard * Change test * Change socket return type
- Loading branch information
1 parent
2e27e46
commit dd2f9a0
Showing
22 changed files
with
317 additions
and
132 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
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,90 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"github.com/google/uuid" | ||
"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/amqp" | ||
"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/stream" | ||
"os" | ||
"time" | ||
) | ||
|
||
func CheckErr(err error) { | ||
if err != nil { | ||
fmt.Printf("%s ", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func CreateArrayMessagesForTesting(batchMessages int) []*amqp.Message { | ||
var arr []*amqp.Message | ||
for z := 0; z < batchMessages; z++ { | ||
arr = append(arr, amqp.NewMessage([]byte("1234567890"))) | ||
} | ||
return arr | ||
} | ||
|
||
func main() { | ||
reader := bufio.NewReader(os.Stdin) | ||
// Set log level, not mandatory by default is INFO | ||
//stream.SetLevelInfo(stream.DEBUG) | ||
|
||
fmt.Println("Getting started with Streaming client for RabbitMQ") | ||
fmt.Println("Connecting to RabbitMQ streaming ...") | ||
|
||
env, err := stream.NewEnvironment( | ||
stream.NewEnvironmentOptions(). | ||
SetHost("localhost"). | ||
SetPort(5552). | ||
SetUser("guest"). | ||
SetPassword("guest"). | ||
SetMaxConsumersPerClient(1)) | ||
CheckErr(err) | ||
// Create a stream, you can create streams without any option like: | ||
// err = env.DeclareStream(streamName, nil) | ||
// it is a best practise to define a size, 1GB for example: | ||
streamName := uuid.New().String() | ||
err = env.DeclareStream(streamName, | ||
&stream.StreamOptions{ | ||
MaxLengthBytes: stream.ByteCapacity{}.GB(2), | ||
}, | ||
) | ||
|
||
CheckErr(err) | ||
|
||
producer, err := env.NewProducer(streamName, nil, nil) | ||
CheckErr(err) | ||
|
||
go func() { | ||
for i := 0; i < 2; i++ { | ||
_, err = producer.BatchPublish(context.Background(), CreateArrayMessagesForTesting(100)) | ||
time.Sleep(1 * time.Second) | ||
} | ||
}() | ||
|
||
counter := 0 | ||
handleMessages := func(consumerContext stream.ConsumerContext, message *amqp.Message) { | ||
counter = counter + 1 | ||
fmt.Printf("messages consumed: %d \n ", counter) | ||
} | ||
|
||
consumer, err := env.NewConsumer(context.TODO(), streamName, | ||
handleMessages, | ||
nil, | ||
stream.NewConsumerOptions(). | ||
SetConsumerName("my_consumer"). // set a consumer name | ||
SetOffset(stream.OffsetSpecification{}.Offset(100))) // start specific offset, in this case we start from the 100 so it will consume 100 messages | ||
CheckErr(err) | ||
|
||
fmt.Println("Press any key to stop ") | ||
_, _ = reader.ReadString('\n') | ||
err = producer.Close() | ||
CheckErr(err) | ||
err = consumer.Close() | ||
CheckErr(err) | ||
err = env.DeleteStream(streamName) | ||
CheckErr(err) | ||
|
||
} |
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
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
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
Oops, something went wrong.