Polish examples
diff --git a/core/api.go b/core/api.go
index 8a6fdd3..22eef1d 100644
--- a/core/api.go
+++ b/core/api.go
@@ -118,12 +118,31 @@
}
}
+type ConsumerModel int
+
+const (
+ CoCurrently = ConsumerModel(1)
+ Orderly = ConsumerModel(2)
+)
+
+func (mode ConsumerModel) String() string {
+ switch mode {
+ case CoCurrently:
+ return "CoCurrently"
+ case Orderly:
+ return "Orderly"
+ default:
+ return "Unknown"
+ }
+}
+
// PushConsumerConfig define a new consumer.
type PushConsumerConfig struct {
ClientConfig
ThreadCount int
MessageBatchMaxSize int
Model MessageModel
+ ConsumerModel ConsumerModel
}
func (config *PushConsumerConfig) String() string {
@@ -142,6 +161,9 @@
str = strJoin(str, "MessageModel", config.Model.String())
}
+ if config.ConsumerModel != 0 {
+ str = strJoin(str, "ConsumerModel", config.ConsumerModel.String())
+ }
return str + "]"
}
diff --git a/core/push_consumer.go b/core/push_consumer.go
index 90e1454..29da7fb 100644
--- a/core/push_consumer.go
+++ b/core/push_consumer.go
@@ -32,11 +32,11 @@
import "C"
import (
+ "errors"
"fmt"
log "github.com/sirupsen/logrus"
"sync"
"unsafe"
- "errors"
)
type ConsumeStatus int
@@ -183,10 +183,17 @@
}
- err = rmqError(C.RegisterMessageCallback(cconsumer, (C.MessageCallBack)(unsafe.Pointer(C.callback_cgo))))
+ if config.ConsumerModel != 0 {
+ switch config.ConsumerModel {
+ case Orderly:
+ err = rmqError(C.RegisterMessageCallbackOrderly(cconsumer, (C.MessageCallBack)(unsafe.Pointer(C.callback_cgo))))
+ case CoCurrently:
+ err = rmqError(C.RegisterMessageCallback(cconsumer, (C.MessageCallBack)(unsafe.Pointer(C.callback_cgo))))
+ }
+ if err != NIL {
+ return nil, err
+ }
- if err != NIL {
- return nil, err
}
consumer.cconsumer = cconsumer