|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#include <stdio.h> |
| 19 | +#include "CBatchMessage.h" |
| 20 | +#include "CCommon.h" |
| 21 | +#include "CMessage.h" |
| 22 | +#include "CProducer.h" |
| 23 | +#include "CSendResult.h" |
| 24 | + |
| 25 | +void StartSendMessage(CProducer* producer) { |
| 26 | + int i = 0; |
| 27 | + int ret_code = 0; |
| 28 | + char body[128]; |
| 29 | + CBatchMessage* batchMessage = CreateBatchMessage("T_TestTopic"); |
| 30 | + |
| 31 | + for (i = 0; i < 10; i++) { |
| 32 | + CMessage* msg = CreateMessage("T_TestTopic"); |
| 33 | + SetMessageTags(msg, "Test_Tag"); |
| 34 | + SetMessageKeys(msg, "Test_Keys"); |
| 35 | + memset(body, 0, sizeof(body)); |
| 36 | + snprintf(body, sizeof(body), "new message body, index %d", i); |
| 37 | + SetMessageBody(msg, body); |
| 38 | + AddMessage(batchMessage, msg); |
| 39 | + } |
| 40 | + CSendResult result; |
| 41 | + int ok = SendBatchMessage(producer, batchMessage, &result); |
| 42 | + printf("SendBatchMessage is %s .....\n", ok == 0 ? "Success" : ok == 11 ? "FAILED" : " It is null value"); |
| 43 | + DestroyBatchMessage(batchMessage); |
| 44 | +} |
| 45 | + |
| 46 | +void CreateProducerAndStartSendMessage() { |
| 47 | + printf("Producer Initializing.....\n"); |
| 48 | + CProducer* producer = CreateProducer("Group_producer"); |
| 49 | + SetProducerNameServerAddress(producer, "127.0.0.1:9876"); |
| 50 | + StartProducer(producer); |
| 51 | + printf("Producer start.....\n"); |
| 52 | + StartSendMessage(producer); |
| 53 | + ShutdownProducer(producer); |
| 54 | + DestroyProducer(producer); |
| 55 | + printf("Producer Shutdown!\n"); |
| 56 | +} |
| 57 | + |
| 58 | +int main(int argc, char* argv[]) { |
| 59 | + printf("Send Batch.....\n"); |
| 60 | + CreateProducerAndStartSendMessage(); |
| 61 | + return 0; |
| 62 | +} |
0 commit comments