forked from apache/pulsar
-
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.
Pulsar Go client library (apache#1764)
* WIP - Pulsar Go client library * Refactored configurations to use struct instead of builder * Simplified methods terminology * Fixed typos * Refactored message builder * More refactoring from comments * More polishing and using context * Implemented message properties * Use standard include and link paths * Removed dependencies on library for saving pointers * Remoed all Async methods (except producer.SendAsync() from public API * MessageBuilder -> ProducerMessage * Allow to configure custom loggers from Go * Cleaned up logger * Use fully qualified package name in example * Added Unit tests
- Loading branch information
Showing
36 changed files
with
2,818 additions
and
30 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
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
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
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,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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#pragma GCC visibility push(default) | ||
|
||
typedef struct _pulsar_string_map pulsar_string_map_t; | ||
|
||
pulsar_string_map_t *pulsar_string_map_create(); | ||
void pulsar_string_map_free(pulsar_string_map_t *map); | ||
|
||
int pulsar_string_map_size(pulsar_string_map_t *map); | ||
|
||
void pulsar_string_map_put(pulsar_string_map_t *map, const char *key, const char *value); | ||
|
||
const char *pulsar_string_map_get(pulsar_string_map_t *map, const char *key); | ||
|
||
const char *pulsar_string_map_get_key(pulsar_string_map_t *map, int idx); | ||
const char *pulsar_string_map_get_value(pulsar_string_map_t *map, int idx); | ||
|
||
#pragma GCC visibility pop | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
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
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
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
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
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,60 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#include <pulsar/c/string_map.h> | ||
|
||
#include "c_structs.h" | ||
|
||
pulsar_string_map_t *pulsar_string_map_create() { return new pulsar_string_map_t; } | ||
|
||
void pulsar_string_map_free(pulsar_string_map_t *map) { delete map; } | ||
|
||
int pulsar_string_map_size(pulsar_string_map_t *map) { return map->map.size(); } | ||
|
||
void pulsar_string_map_put(pulsar_string_map_t *map, const char *key, const char *value) { | ||
map->map[key] = value; | ||
} | ||
|
||
const char *pulsar_string_map_get(pulsar_string_map_t *map, const char *key) { | ||
std::map<std::string, std::string>::iterator it = map->map.find(key); | ||
|
||
if (it == map->map.end()) { | ||
return NULL; | ||
} else { | ||
return it->second.c_str(); | ||
} | ||
} | ||
|
||
const char *pulsar_string_map_get_key(pulsar_string_map_t *map, int idx) { | ||
std::map<std::string, std::string>::iterator it = map->map.begin(); | ||
while (idx-- > 0) { | ||
++it; | ||
} | ||
|
||
return it->first.c_str(); | ||
} | ||
|
||
const char *pulsar_string_map_get_value(pulsar_string_map_t *map, int idx) { | ||
std::map<std::string, std::string>::iterator it = map->map.begin(); | ||
while (idx-- > 0) { | ||
++it; | ||
} | ||
|
||
return it->second.c_str(); | ||
} |
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
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
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
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
60 changes: 60 additions & 0 deletions
60
pulsar-client-go/examples/consumer-listener/consumer-listener.go
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,60 @@ | ||
// | ||
// 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 ( | ||
"github.com/apache/incubator-pulsar/pulsar-client-go/pulsar" | ||
"fmt" | ||
"log" | ||
) | ||
|
||
func main() { | ||
client, err := pulsar.NewClient(pulsar.ClientOptions{URL: "pulsar://localhost:6650"}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
defer client.Close() | ||
|
||
channel := make(chan pulsar.ConsumerMessage) | ||
|
||
consumer, err := client.Subscribe(pulsar.ConsumerOptions{ | ||
Topic: "my-topic", | ||
SubscriptionName: "my-subscription", | ||
Type: pulsar.Shared, | ||
MessageChannel: channel, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
defer consumer.Close() | ||
|
||
// Receive messages from channel. The channel returns a struct which contains message and the consumer from where | ||
// the message was received. It's not necessary here since we have 1 single consumer, but the channel could be | ||
// shared across multiple consumers as well | ||
for cm := range channel { | ||
msg := cm.Message | ||
fmt.Printf("Received message msgId: %s -- content: '%s'\n", | ||
msg.ID(), string(msg.Payload())) | ||
|
||
consumer.Ack(msg) | ||
} | ||
} |
Oops, something went wrong.