Support Send Message and Push Consume Message
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..3e83233
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,2 @@
+## How to Contribute
+ Contributions are warmly welcome! Be it trivial cleanup, major new feature or other suggestion. Read this [how to contribute](http://rocketmq.apache.org/docs/how-to-contribute/) guide for more details.
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..0130891
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (properties) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
\ No newline at end of file
diff --git a/README.md b/README.md
index 7ac7996..9b7deb9 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,36 @@
-# rocketmq-client-go
+## RocketMQ Client Go [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
+
+* RocketMQ Go client is developed on top of [rocketmq-client-go](https://github.com/apache/rocketmq-client-go), which has been proven robust and widely adopted within Alibaba Group by many business units for more than three years.
+
+----------
+## Features
+At present, this SDK supports
+* sending message in synchronous mode
+* consuming message using push model
+
+----------
+## How to use
+* Step-by-step instruction are provided in [RocketMQ Go Client Introduction](https://github.com/apache/rocketmq-client-go/doc/Introduction.md)
+* Consult [RocketMQ Quick Start](https://rocketmq.apache.org/docs/quick-start/) to setup rocketmq broker and nameserver.
+
+----------
+## Apache RocketMQ Community
+* [RocketMQ Community Projects](https://github.com/apache/rocketmq-externals)
+
+----------
+## Contact us
+* Mailing Lists: <https://rocketmq.apache.org/about/contact/>
+* Home: <https://rocketmq.apache.org>
+* Docs: <https://rocketmq.apache.org/docs/quick-start/>
+* Issues: <https://github.com/apache/rocketmq-client-python/issues>
+* Ask: <https://stackoverflow.com/questions/tagged/rocketmq>
+* Slack: <https://rocketmq-community.slack.com/>
+
+----------
+## How to Contribute
+ Contributions are warmly welcome! Be it trivial cleanup, major new feature or other suggestion. Read this [how to contribute](http://rocketmq.apache.org/docs/how-to-contribute/) guide for more details.
+
+
+----------
+## License
+ [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) Copyright (C) Apache Software Foundation
diff --git a/changelog b/changelog
new file mode 100755
index 0000000..2a23ffc
--- /dev/null
+++ b/changelog
@@ -0,0 +1,3 @@
+version 1.0.0 @2018.10.29
+ * Initialize version of Go client.
+
diff --git a/doc/Introduction.md b/doc/Introduction.md
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/doc/Introduction.md
@@ -0,0 +1 @@
+
diff --git a/src/client/client.go b/src/client/client.go
new file mode 100644
index 0000000..c4a9a59
--- /dev/null
+++ b/src/client/client.go
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client
+
+func Version() (version string){
+ return GetVersion()
+}
+
+type Message interface {
+}
+type MessageExt interface {
+}
+type Producer interface {
+}
+type PushConsumer interface {
+}
\ No newline at end of file
diff --git a/src/client/consume.go b/src/client/consume.go
new file mode 100644
index 0000000..d28aae2
--- /dev/null
+++ b/src/client/consume.go
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client
+
+//#cgo CFLAGS: -I/usr/local/include/rocketmq
+//#cgo LDFLAGS: -L/usr/local/lib -lrocketmq
+//typedef struct CMessageExt CMessageExt;
+//typedef struct CPushConsumer CPushConsumer;
+//#include "CMessageExt.h"
+//#include "CPushConsumer.h"
+import "C"
+
+//export ConsumeMessageCallback
+func ConsumeMessageCallback(consumer *C.struct_CPushConsumer,msg *C.struct_CMessageExt) (C.int) {
+ return C.int(ConsumeMessageInner(consumer,msg))
+}
diff --git a/src/client/consumestatus.go b/src/client/consumestatus.go
new file mode 100644
index 0000000..55fd015
--- /dev/null
+++ b/src/client/consumestatus.go
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client
+
+type ConsumeStatus int
+
+const (
+ ConsumeSuccess ConsumeStatus = iota // value --> 0
+ ReConsumeLater // value --> 1
+)
+func (status ConsumeStatus) String() string {
+ switch status {
+ case ConsumeSuccess:
+ return "ConsumeSuccess"
+ case ReConsumeLater:
+ return "ReConsumeLater"
+ default:
+ return "Unknown"
+ }
+}
\ No newline at end of file
diff --git a/src/client/messageExt.go b/src/client/messageExt.go
new file mode 100644
index 0000000..c61ef11
--- /dev/null
+++ b/src/client/messageExt.go
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client
+
+//#cgo CFLAGS: -I/usr/local/include/rocketmq
+//#cgo LDFLAGS: -L/usr/local/lib -lrocketmq
+//typedef struct CMessageExt CMessageExt;
+//#include "CMessageExt.h"
+import "C"
+
+//type MessageExt C.struct_CMessageExt
+
+func GetMessageTopic(msg MessageExt)(topic string){
+ topic = C.GoString(C.GetMessageTopic(msg.(*C.struct_CMessageExt)))
+ return
+}
+func GetMessageTags(msg MessageExt)(tags string){
+ tags = C.GoString(C.GetMessageTags(msg.(*C.struct_CMessageExt)))
+ return
+}
+func GetMessageKeys(msg MessageExt)(keys string){
+ keys = C.GoString(C.GetMessageKeys(msg.(*C.struct_CMessageExt)))
+ return
+}
+func GetMessageBody(msg MessageExt)(body string){
+ body = C.GoString(C.GetMessageBody(msg.(*C.struct_CMessageExt)))
+ return
+}
+func GetMessageProperty(msg MessageExt,key string)(value string){
+ value = C.GoString(C.GetMessageProperty(msg.(*C.struct_CMessageExt),C.CString(key)))
+ return
+}
+func GetMessageId(msg MessageExt)(msgId string){
+ msgId = C.GoString(C.GetMessageId(msg.(*C.struct_CMessageExt)))
+ return
+}
\ No newline at end of file
diff --git a/src/client/producer.go b/src/client/producer.go
new file mode 100644
index 0000000..a0a1e91
--- /dev/null
+++ b/src/client/producer.go
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client
+
+//#cgo CFLAGS: -I/usr/local/include/rocketmq
+//#cgo LDFLAGS: -L/usr/local/lib -lrocketmq
+//typedef struct CMessage CMessage;
+//typedef struct CProducer CProducer;
+//#include "CMessage.h"
+//#include "CProducer.h"
+import "C"
+
+//type Producer C.struct_CProducer
+//type Message C.struct_CMessage
+//type SendResult C.struct_CSendResult
+//type PushConsumer C.struct_CPushConsumer
+//type MessageExt C.struct_CMessageExt
+
+func CreateMessage(topic string)(msg Message){
+ msg = C.CreateMessage(C.CString(topic))
+ return msg;
+}
+func DestroyMessage(msg Message){
+ C.DestroyMessage(msg.(*C.struct_CMessage))
+}
+func SetMessageKeys(msg Message,keys string)(int){
+ return int(C.SetMessageKeys(msg.(*C.struct_CMessage),C.CString(keys)))
+}
+func SetMessageBody(msg Message,body string)(int){
+ return int(C.SetMessageBody(msg.(*C.struct_CMessage),C.CString(body)))
+}
+func CreateProducer(groupId string)(producer Producer){
+ producer = C.CreateProducer(C.CString(groupId))
+ return producer;
+}
+func DestroyProducer(producer Producer){
+ C.DestroyProducer(producer.(*C.struct_CProducer))
+}
+func StartProducer(producer Producer)(int){
+ return int(C.StartProducer(producer.(*C.struct_CProducer)))
+}
+func ShutdownProducer(producer Producer)(int){
+ return int(C.ShutdownProducer(producer.(*C.struct_CProducer)))
+}
+func SetProducerNameServerAddress(producer Producer, nameServer string)(int){
+ return int(C.SetProducerNameServerAddress(producer.(*C.struct_CProducer),C.CString(nameServer)))
+}
+func SetProducerSessionCredentials(producer Producer, accessKey string, secretKey string, channel string) (int) {
+ ret := C.SetProducerSessionCredentials(producer.(*C.struct_CProducer),
+ C.CString(accessKey),
+ C.CString(secretKey),
+ C.CString(channel))
+ return int(ret)
+}
+func SendMessageSync(producer Producer, msg Message)(sendResult SendResult){
+ var sr C.struct__SendResult_
+ C.SendMessageSync(producer.(*C.struct_CProducer),msg.(*C.struct_CMessage),&sr)
+ sendResult.Status = SendStatus(sr.sendStatus)
+ sendResult.MsgId = C.GoString(&sr.msgId[0])
+ sendResult.Offset = int64(sr.offset)
+ return sendResult
+}
\ No newline at end of file
diff --git a/src/client/pushconsumer.go b/src/client/pushconsumer.go
new file mode 100644
index 0000000..f6cb3ea
--- /dev/null
+++ b/src/client/pushconsumer.go
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client
+
+//#cgo CFLAGS: -I/usr/local/include/rocketmq
+//#cgo LDFLAGS: -L/usr/local/lib -lrocketmq
+//typedef struct CMessageExt CMessageExt;
+//typedef struct CPushConsumer CPushConsumer;
+//#include "CMessageExt.h"
+//#include "CPushConsumer.h"
+//extern int ConsumeMessageCallback(CPushConsumer *consumer,CMessageExt *msg);
+//int ConsumerMessageCallBackInner(CPushConsumer *consumer, CMessageExt *msg) {
+//return ConsumeMessageCallback(consumer,msg);
+//}
+//int SetConsumerMessageCallBackInner(CPushConsumer *consumer) {
+//return RegisterMessageCallback(consumer,ConsumerMessageCallBackInner);
+//}
+import "C"
+import "fmt"
+
+//type PushConsumer C.struct_CPushConsumer
+//type MessageExt C.struct_CMessageExt
+type Callback func(msg MessageExt) ConsumeStatus
+
+func CreatePushConsumer(groupId string) (consumer PushConsumer) {
+ consumer = C.CreatePushConsumer(C.CString(groupId))
+ return consumer;
+}
+func DestroyPushConsumer(consumer PushConsumer) {
+ consumer = C.DestroyPushConsumer(consumer.(*C.struct_CPushConsumer))
+ return
+}
+func StartPushConsumer(consumer PushConsumer) int {
+ return int(C.StartPushConsumer(consumer.(*C.struct_CPushConsumer)))
+}
+func ShutdownPushConsumer(consumer PushConsumer) int {
+ return int(C.ShutdownPushConsumer(consumer.(*C.struct_CPushConsumer)))
+}
+func SetPushConsumerGroupID(consumer PushConsumer, groupId string) (int) {
+ return int(C.SetPushConsumerGroupID(consumer.(*C.struct_CPushConsumer), C.CString(groupId)))
+}
+func SetPushConsumerNameServerAddress(consumer PushConsumer, name string) (int) {
+ return int(C.SetPushConsumerNameServerAddress(consumer.(*C.struct_CPushConsumer), C.CString(name)))
+}
+func SetPushConsumerThreadCount(consumer PushConsumer, count int) (int) {
+ return int(C.SetPushConsumerThreadCount(consumer.(*C.struct_CPushConsumer), C.int(count)))
+}
+func SetPushConsumerMessageBatchMaxSize(consumer PushConsumer, size int) (int) {
+ return int(C.SetPushConsumerMessageBatchMaxSize(consumer.(*C.struct_CPushConsumer), C.int(size)))
+}
+func SetPushConsumerInstanceName(consumer PushConsumer, name string) (int) {
+ return int(C.SetPushConsumerInstanceName(consumer.(*C.struct_CPushConsumer), C.CString(name)))
+}
+func SetPushConsumerSessionCredentials(consumer PushConsumer, accessKey string, secretKey string, channel string) (int) {
+ ret := C.SetPushConsumerSessionCredentials(consumer.(*C.struct_CPushConsumer),
+ C.CString(accessKey),
+ C.CString(secretKey),
+ C.CString(channel))
+ return int(ret)
+}
+
+func Subscribe(consumer PushConsumer, topic string, expression string) (int) {
+ return int(C.Subscribe(consumer.(*C.struct_CPushConsumer), C.CString(topic), C.CString(expression)))
+}
+
+var CallBackMap map[PushConsumer]Callback = map[PushConsumer]Callback{}
+
+func RegisterMessageCallback(consumer PushConsumer, callback Callback) (int) {
+ CallBackMap[consumer] = callback
+ ret := C.SetConsumerMessageCallBackInner(consumer.(*C.struct_CPushConsumer))
+ return int(ret)
+}
+func ConsumeMessageInner(consumer PushConsumer, msg MessageExt) (ConsumeStatus) {
+ fmt.Println("ConsumeMessageInner")
+ callback,ok := CallBackMap[consumer]
+ if ok {
+ return callback(msg)
+ }
+ return ReConsumeLater
+}
diff --git a/src/client/sendresult.go b/src/client/sendresult.go
new file mode 100644
index 0000000..2dc0c73
--- /dev/null
+++ b/src/client/sendresult.go
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client
+
+type SendStatus int
+
+const (
+ SendOK SendStatus = iota // value --> 0
+ SendFlushDiskTimeout // value --> 1
+ SendFlushSlaveTimeout // value --> 2
+ SendSlaveNotAvailable // value --> 3
+)
+func (status SendStatus) String() string {
+ switch status {
+ case SendOK:
+ return "SendOK"
+ case SendFlushDiskTimeout:
+ return "SendFlushDiskTimeout"
+ case SendFlushSlaveTimeout:
+ return "SendFlushSlaveTimeout"
+ case SendSlaveNotAvailable:
+ return "SendSlaveNotAvailable"
+ default:
+ return "Unknown"
+ }
+}
+type SendResult struct {
+ Status SendStatus
+ MsgId string
+ Offset int64
+}
\ No newline at end of file
diff --git a/src/client/version.go b/src/client/version.go
new file mode 100644
index 0000000..2137825
--- /dev/null
+++ b/src/client/version.go
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client
+
+var GO_CLIENT_VERSION = "Go Client V1.0.0, BuildTime:2018.10.30"
+func GetVersion() (version string){
+ return GO_CLIENT_VERSION
+}
diff --git a/src/sample/example_common.go b/src/sample/example_common.go
new file mode 100644
index 0000000..10c2a40
--- /dev/null
+++ b/src/sample/example_common.go
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import "fmt"
+import "../client"
+
+func ExampleVersion() {
+ fmt.Println("Version :", client.GetVersion())
+}
\ No newline at end of file
diff --git a/src/sample/example_producer.go b/src/sample/example_producer.go
new file mode 100644
index 0000000..4985ad8
--- /dev/null
+++ b/src/sample/example_producer.go
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import "fmt"
+import "../client"
+
+func ExampleSendMessage() {
+ fmt.Println("Start Send Message..")
+ namesvr := "172.17.0.5:9876"
+ topic := "T_TestTopic"
+ keys := "testKeys"
+ body := "testBody"
+ //Create Producer
+ producer := client.CreateProducer("testGroupId")
+ fmt.Println("Create Producer")
+ client.SetProducerNameServerAddress(producer, namesvr)
+ fmt.Println("Set Producer Nameserver:", namesvr)
+ client.StartProducer(producer)
+ fmt.Println("Start Producer")
+
+ for i := 1; i <= 10; i++ {
+ //Create Message
+ msg := client.CreateMessage(topic)
+ fmt.Println("Create Message, Topic:", topic)
+ client.SetMessageKeys(msg, keys)
+ fmt.Println("Set Message Keys:", keys)
+ client.SetMessageBody(msg, body)
+ fmt.Println("Set Message body:", body)
+
+ sendresult := client.SendMessageSync(producer, msg)
+ fmt.Println("Send Message OK")
+ fmt.Println("SendStatus:", sendresult.Status)
+ fmt.Println("SendResult:", sendresult)
+ client.DestroyMessage(msg)
+ }
+ client.ShutdownProducer(producer)
+ client.DestroyProducer(producer)
+}
diff --git a/src/sample/example_pushconsumer.go b/src/sample/example_pushconsumer.go
new file mode 100644
index 0000000..392dfe7
--- /dev/null
+++ b/src/sample/example_pushconsumer.go
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import "fmt"
+import "../client"
+
+func ConsumeMessage(msg client.MessageExt) (client.ConsumeStatus) {
+ fmt.Println("ConsumeMessage")
+ fmt.Println("Message topic",client.GetMessageTopic(msg))
+ fmt.Println("MessageId",client.GetMessageId(msg))
+ return client.ConsumeSuccess
+}
+
+func ExamplePushConsumeMessage() {
+ fmt.Println("Start Send Message..")
+ namesvr := "172.17.0.5:9876"
+ topic := "T_TestTopic"
+ expression := "*"
+ //Create Producer
+ consumer := client.CreatePushConsumer("testGroupId")
+ fmt.Println("Create Push Consumer")
+ client.SetPushConsumerNameServerAddress(consumer, namesvr)
+ fmt.Println("Set Push Consumer Nameserver:", namesvr)
+
+ client.Subscribe(consumer, topic, expression)
+ fmt.Println("Set Push Consumer Subscribe,Topic:", topic," Exp:", expression)
+
+ client.RegisterMessageCallback(consumer,ConsumeMessage)
+ client.StartPushConsumer(consumer)
+ fmt.Println("Start Push Consumer")
+ fmt.Scan()
+ select{}
+ client.ShutdownPushConsumer(consumer)
+ client.DestroyPushConsumer(consumer)
+}
diff --git a/src/sample/main.go b/src/sample/main.go
new file mode 100644
index 0000000..4a040e3
--- /dev/null
+++ b/src/sample/main.go
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import "fmt"
+
+func main() {
+ fmt.Println("Start Sample Main Function......")
+ ExampleVersion()
+ ExampleSendMessage()
+ ExamplePushConsumeMessage()
+ fmt.Scan()
+}
diff --git a/src/test/client_test.go b/src/test/client_test.go
new file mode 100644
index 0000000..3b12421
--- /dev/null
+++ b/src/test/client_test.go
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client_test
+
+import (
+ "fmt"
+ "testing"
+ "../client"
+)
+
+func TestVersion(test *testing.T){
+ fmt.Println("-----TestGetVersion Start----")
+ version := client.Version();
+ fmt.Println(version)
+ fmt.Println("-----TestGetVersion Finish----")
+}
diff --git a/src/test/messageExt_test.go b/src/test/messageExt_test.go
new file mode 100644
index 0000000..a241c28
--- /dev/null
+++ b/src/test/messageExt_test.go
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client_test
+
+import (
+ "fmt"
+ "testing"
+ "../client"
+)
+
+func TestGetMessageTopic(test *testing.T){
+ fmt.Println("-----TestGetMessageTopic Start----")
+ msg := client.CreateMessage("testTopic")
+ client.DestroyMessage(msg)
+ fmt.Println("-----TestGetMessageTopic Finish----")
+}
diff --git a/src/test/producer_test.go b/src/test/producer_test.go
new file mode 100644
index 0000000..66e2caf
--- /dev/null
+++ b/src/test/producer_test.go
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client_test
+
+import "fmt"
+import "testing"
+import "../client"
+
+func TestCreateMessage(test *testing.T){
+ fmt.Println("-----TestCreateMessage Start----")
+ client.CreateMessage("testTopic")
+ fmt.Println("-----TestCreateMessage Finish----")
+}
+func TestDestroyMessage(test *testing.T){
+ fmt.Println("-----TestCreateMessage Start----")
+ msg := client.CreateMessage("testTopic")
+ client.DestroyMessage(msg)
+ fmt.Println("-----TestCreateMessage Finish----")
+}
+func TestSetMessageKeys(test *testing.T){
+ fmt.Println("-----TestSetMessageKeys Start----")
+ msg := client.CreateMessage("testTopic")
+ len := client.SetMessageKeys(msg,"testKey")
+ fmt.Println("Len:",len)
+ client.DestroyMessage(msg)
+ fmt.Println("-----TestCreateMessage Finish----")
+}
+func TestCreateProducer(test *testing.T){
+ fmt.Println("-----TestCreateProducer Start----")
+ client.CreateProducer("testGroupId")
+ fmt.Println("-----TestCreateProducer Finish----")
+}
diff --git a/src/test/pushconsumer_test.go b/src/test/pushconsumer_test.go
new file mode 100644
index 0000000..7083713
--- /dev/null
+++ b/src/test/pushconsumer_test.go
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client_test
+
+import "fmt"
+import "testing"
+import "../client"
+
+func TestCreatePushConsumer(test *testing.T){
+ fmt.Println("-----TestCreateProducer Start----")
+ consumer := client.CreatePushConsumer("testGroupId")
+ client.DestroyPushConsumer(consumer)
+ fmt.Println("-----TestCreateProducer Finish----")
+}
diff --git a/src/test/version_test.go b/src/test/version_test.go
new file mode 100644
index 0000000..59f35ba
--- /dev/null
+++ b/src/test/version_test.go
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package client_test
+
+import (
+ "fmt"
+ "testing"
+ "../client"
+)
+
+func TestGetVersion(test *testing.T){
+ fmt.Println("-----TestGetVersion Start----")
+ version := client.GetVersion();
+ fmt.Println(version)
+ fmt.Println("-----TestGetVersion Finish----")
+}