-
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.
* starting * topology * topology * producer * producer * producer * messagerype * confirms * producer make it better * bugfix + consumer * temp consumer * working * deserializer * error handling * bugfix + correlation * make log better * default serializer * echange bind * active passive * make it better * return response * partitioner * bugfix * error handling * minor * retry moved * waiting error moved * protobuf support * inject header in channel * readme * readme * examples
- Loading branch information
Showing
6 changed files
with
224 additions
and
7 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
Binary file not shown.
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,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"rabbit" | ||
"time" | ||
) | ||
|
||
func TestMessageHandler(test string, producer rabbit.IProducer) func(message interface{}, header map[string]interface{}) rabbit.HandlerResponse { | ||
return func(message interface{}, header map[string]interface{}) rabbit.HandlerResponse { | ||
testMessage := message.(TestMessage) | ||
log.Println("executing testMessage, test: " + test) | ||
log.Println(testMessage) | ||
log.Println(fmt.Sprintf("header: %v", header)) | ||
time.Sleep(500 * time.Millisecond) | ||
err := producer.Send(message, "", "test", "correlation", "", nil, rabbit.Json) | ||
if err != nil { | ||
log.Println("Error sending the message") | ||
return rabbit.Err | ||
} | ||
return rabbit.Completed | ||
} | ||
} | ||
|
||
func ProtoMessageHandler() func(message interface{}, header map[string]interface{}) rabbit.HandlerResponse { | ||
return func(message interface{}, header map[string]interface{}) rabbit.HandlerResponse { | ||
testMessage := message.(Test) | ||
log.Printf("Id: %d", testMessage.GetId()) | ||
log.Printf("Label: %s", testMessage.GetLabel()) | ||
time.Sleep(500 * time.Millisecond) | ||
return rabbit.Completed | ||
} | ||
} |
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,82 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"rabbit" | ||
"reflect" | ||
"runtime" | ||
"time" | ||
|
||
"github.com/golang/protobuf/proto" | ||
) | ||
|
||
type TestMessage struct { | ||
Id int | ||
Name string | ||
} | ||
|
||
var roundrobin int64 = 0 | ||
|
||
func main() { | ||
|
||
runtime.GOMAXPROCS(4) | ||
|
||
logger := rabbit.CreateLogger( | ||
func(l string) { log.Println(l) }, | ||
func(l string) { log.Println(l) }, | ||
func(l string) { log.Println(l) }, | ||
func(l string) { log.Fatal(l) }, | ||
func(l string) { log.Println(l) }, | ||
rabbit.Debug) | ||
|
||
rabbit.Initialize(logger, "amqp://guest:guest@localhost:5672/") | ||
rabbit.TopologyConfiguration(). | ||
DeclareExchange("test.output", "topic", true, false, false, nil). | ||
DeclareExchange("consumer.output", "fanout", true, false, false, nil). | ||
DeclareQueue("test.inbound", true, false, false, nil). | ||
BindQueue("test.inbound", "#", "test.output", nil). | ||
DeclareQueue("consumer.inbound", true, false, false, map[string]interface{}{ | ||
"x-message-ttl": int32(600000), | ||
}). | ||
BindQueue("consumer.inbound", "", "consumer.output", nil). | ||
Complete() | ||
|
||
producer := rabbit.ConfigureProducer(3, "test.output", rabbit.Transient, true) | ||
consumerProducer := rabbit.ConfigureProducer(3, "consumer.output", rabbit.Transient, true) | ||
|
||
consumer := rabbit.ConfigureConsumer(100, 5*time.Second) | ||
h := TestMessageHandler("teststring", consumerProducer) | ||
consumer.AddHandler("main.TestMessage", reflect.TypeOf(TestMessage{}), h) | ||
|
||
protoH := ProtoMessageHandler() | ||
consumer.AddHandler("main.Test", reflect.TypeOf(Test{}), protoH) | ||
|
||
//consumer.AddRetryHandler("main.TestMessage", reflect.TypeOf(TestMessage{}), h, 10) | ||
partitionerResolver := make(map[reflect.Type]func(message interface{}) int64) | ||
partitionerResolver[reflect.TypeOf(TestMessage{})] = func(message interface{}) int64 { return int64(message.(TestMessage).Id) } | ||
//consumer.StartConsuming("test.inbound", true, true, 1000*time.Millisecond, 1, nil) | ||
consumer.StartConsumingPartitions("test.inbound", true, true, | ||
3000*time.Millisecond, 5*time.Second, 30, partitionerResolver, nil) | ||
|
||
for i := 0; i < 1; i++ { | ||
go func(i int) { | ||
message := TestMessage{i, "test"} | ||
err := producer.Send(message, "testmessage.1", fmt.Sprintf("%d", i), "correlation", "", nil, rabbit.Json) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
protoMessage := &Test{ | ||
Id: proto.Int32(int32(i)), | ||
Label: proto.String("test protobuf"), | ||
} | ||
err2 := producer.Send(protoMessage, "protoMessage.1", fmt.Sprintf("%d", i), "correlation", "", nil, rabbit.Protobuf) | ||
if err2 != nil { | ||
log.Fatal(err2) | ||
} | ||
}(i) | ||
} | ||
|
||
fmt.Scanln() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
syntax = "proto2"; | ||
package main; | ||
|
||
message Test { | ||
required int32 Id = 1; | ||
required string label = 2; | ||
} |