Skip to content

Change PullConsumer model to CLUSTER & format example code style #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.idea
cmake-build-debug/
bin
libs

bin
build
libs/signature/lib
tmp_*
54 changes: 32 additions & 22 deletions example/Producer.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,55 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WIN32
#include <unistd.h>
#endif

#include <stdio.h>

#include "CProducer.h"
#include "CCommon.h"
#include "CMessage.h"
#include "CSendResult.h"

void startSendMessage(CProducer* producer)
{
#ifdef _WIN32
#include <windows.h>
#else

#include <unistd.h>
#include <memory.h>

#endif

void thread_sleep(unsigned milliseconds) {
#ifdef _WIN32
Sleep(milliseconds);
#else
usleep(milliseconds * 1000); // takes microseconds
#endif
}

void startSendMessage(CProducer *producer) {
int i = 0;
char DestMsg[256];
CMessage* msg = CreateMessage("T_TestTopic");
SetMessageTags(msg,"Test_Tag");
SetMessageKeys(msg,"Test_Keys");
CMessage *msg = CreateMessage("T_TestTopic");
SetMessageTags(msg, "Test_Tag");
SetMessageKeys(msg, "Test_Keys");
CSendResult result;
for( i=0; i<10; i++)
{
printf("send one message : %d\n",i);
memset(DestMsg,0,sizeof(DestMsg));
snprintf(DestMsg,255,"New message body: index %d",i);
SetMessageBody(msg,DestMsg);
for (i = 0; i < 10; i++) {
printf("send one message : %d\n", i);
memset(DestMsg, 0, sizeof(DestMsg));
snprintf(DestMsg, 255, "New message body: index %d", i);
SetMessageBody(msg, DestMsg);
SendMessageSync(producer, msg, &result);
printf("Msg Send ID:%s\n",result.msgId);
#ifndef WIN32
sleep(1);
#endif
printf("Msg Send ID:%s\n", result.msgId);
thread_sleep(1000);
}
}


int main(int argc,char * argv [ ])
{
int main(int argc, char *argv[]) {
printf("Producer Initializing.....\n");

CProducer* producer = CreateProducer("Group_producer");
SetProducerNameServerAddress(producer,"172.17.0.2:9876");
CProducer *producer = CreateProducer("Group_producer");
SetProducerNameServerAddress(producer, "172.17.0.2:9876");
StartProducer(producer);
printf("Producer start.....\n");
startSendMessage(producer);
Expand Down
24 changes: 18 additions & 6 deletions example/PullConsumeMessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WIN32
#include <unistd.h>
#endif
#include <stdio.h>


#include <stdio.h>

#include "CPullConsumer.h"
#include "CCommon.h"
#include "CMessageExt.h"
#include "CPullResult.h"
#include "CMessageQueue.h"

#ifdef _WIN32
#include <windows.h>
#else

#include <unistd.h>
#include <memory.h>

#endif

void thread_sleep(unsigned milliseconds) {
#ifdef _WIN32
Sleep(milliseconds);
#else
usleep(milliseconds * 1000); // takes microseconds
#endif
}

int main(int argc,char * argv [])
{
Expand All @@ -39,7 +51,7 @@ int main(int argc,char * argv [])
for( i=0; i<10; i++)
{
printf("Now Running : %d S\n",i*10);
sleep(10);
thread_sleep(10000);
}
ShutdownPullConsumer(consumer);
DestroyPullConsumer(consumer);
Expand Down
56 changes: 30 additions & 26 deletions example/PushConsumeMessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,52 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WIN32
#include <unistd.h>
#else
#include <windows.h>
void sleep(int interval) {
Sleep(interval * 10);
}
#endif
#include <stdio.h>


#include <stdio.h>

#include "CPushConsumer.h"
#include "CCommon.h"
#include "CMessageExt.h"

#ifdef _WIN32
#include <windows.h>
#else

#include <unistd.h>
#include <memory.h>

#endif

void thread_sleep(unsigned milliseconds) {
#ifdef _WIN32
Sleep(milliseconds);
#else
usleep(milliseconds * 1000); // takes microseconds
#endif
}

int doConsumeMessage(struct CPushConsumer * consumer, CMessageExt * msgExt)
{
int doConsumeMessage(struct CPushConsumer *consumer, CMessageExt *msgExt) {
printf("Hello,doConsumeMessage by Application!\n");
printf("Msg Topic:%s\n",GetMessageTopic(msgExt));
printf("Msg Tags:%s\n",GetMessageTags(msgExt));
printf("Msg Keys:%s\n",GetMessageKeys(msgExt));
printf("Msg Body:%s\n",GetMessageBody(msgExt));
printf("Msg Topic:%s\n", GetMessageTopic(msgExt));
printf("Msg Tags:%s\n", GetMessageTags(msgExt));
printf("Msg Keys:%s\n", GetMessageKeys(msgExt));
printf("Msg Body:%s\n", GetMessageBody(msgExt));
return E_CONSUME_SUCCESS;
}


int main(int argc,char * argv [])
{
int main(int argc, char *argv[]) {
int i = 0;
printf("PushConsumer Initializing....\n");
CPushConsumer* consumer = CreatePushConsumer("Group_Consumer_Test");
SetPushConsumerNameServerAddress(consumer,"172.17.0.2:9876");
Subscribe(consumer,"T_TestTopic","*");
RegisterMessageCallback(consumer,doConsumeMessage);
CPushConsumer *consumer = CreatePushConsumer("Group_Consumer_Test");
SetPushConsumerNameServerAddress(consumer, "172.17.0.2:9876");
Subscribe(consumer, "T_TestTopic", "*");
RegisterMessageCallback(consumer, doConsumeMessage);
StartPushConsumer(consumer);
printf("Push Consumer Start...\n");
for( i=0; i<10; i++)
{
printf("Now Running : %d S\n",i*10);
sleep(10);
for (i = 0; i < 10; i++) {
printf("Now Running : %d S\n", i * 10);
thread_sleep(10000);
}
ShutdownPushConsumer(consumer);
DestroyPushConsumer(consumer);
Expand Down
2 changes: 1 addition & 1 deletion src/consumer/DefaultMQPullConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ DefaultMQPullConsumer::DefaultMQPullConsumer(const string& groupname)
string gname = groupname.empty() ? DEFAULT_CONSUMER_GROUP : groupname;
setGroupName(gname);

setMessageModel(BROADCASTING);
setMessageModel(CLUSTERING);
}

DefaultMQPullConsumer::~DefaultMQPullConsumer() {
Expand Down