pulsar-client 2.4.1.pre.beta.4 → 2.6.1.pre.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +7 -0
- data/.travis.yml +13 -2
- data/Gemfile.lock +5 -5
- data/README.md +5 -3
- data/Rakefile +1 -1
- data/bin/example-consumer +7 -4
- data/bin/example-producer +8 -5
- data/ext/bindings/client.cpp +22 -0
- data/ext/bindings/client.hpp +3 -0
- data/ext/bindings/consumer.cpp +18 -0
- data/ext/bindings/consumer.hpp +1 -0
- data/ext/bindings/extconf.rb +1 -0
- data/ext/bindings/logger.cpp +23 -0
- data/ext/bindings/logger.hpp +17 -0
- data/ext/bindings/message.cpp +43 -2
- data/ext/bindings/message.hpp +5 -1
- data/ext/bindings/producer.cpp +18 -0
- data/ext/bindings/producer.hpp +1 -0
- data/ext/bindings/stringmap.cpp +33 -0
- data/ext/bindings/stringmap.hpp +13 -0
- data/ext/bindings/util.cpp +165 -5
- data/lib/pulsar/client.rb +1 -1
- data/lib/pulsar/client/version.rb +1 -1
- data/lib/pulsar/client_configuration.rb +85 -10
- data/lib/pulsar/consumer_configuration.rb +1 -1
- data/lib/pulsar/producer.rb +5 -2
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0812c85307bcd4017c169592a1547e8249a4193f2d381b0f845f6ce27ab637ec'
|
4
|
+
data.tar.gz: a5581a355348dc9eec95184dfe1a1ff92f2a0858e871c22d6f7cd97f513f50da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76e1855a6cfc363fafe991fbe2e5bd99c9e8f844f7107c79d2494a65185703ea32f30f7b626bcbf0bd26d38227cc7b42f66baee2d15c023fc8d1ea8a115f8f21
|
7
|
+
data.tar.gz: 51cb6884e39d20e8806d17a4ae76954c30b14ef7f19e7c49540ec15411c60845d8c871b03bd0afbf18f17982c2329af60db77a4f4d6ab772b320cba263ad3be7
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
+
dist: bionic # ubuntu 18.04
|
1
2
|
sudo: false
|
2
3
|
language: ruby
|
3
4
|
rvm:
|
4
|
-
- 2.4.
|
5
|
-
|
5
|
+
- 2.4.9 # oldest pre-install on bionic
|
6
|
+
install:
|
7
|
+
- sudo apt-get -y install apt-utils automake
|
8
|
+
# - sudo apt-get upgrade libstdc++6
|
9
|
+
- wget https://archive.apache.org/dist/pulsar/pulsar-2.6.1/DEB/apache-pulsar-client.deb
|
10
|
+
- wget https://archive.apache.org/dist/pulsar/pulsar-2.6.1/DEB/apache-pulsar-client-dev.deb
|
11
|
+
- sudo apt-get -y install ./apache-pulsar-client.deb
|
12
|
+
- sudo apt-get -y install ./apache-pulsar-client-dev.deb
|
13
|
+
- gem install bundler -v 1.16.1
|
14
|
+
- bundle install
|
15
|
+
script:
|
16
|
+
- rake
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pulsar-client (
|
5
|
-
rake-compiler
|
6
|
-
rice
|
4
|
+
pulsar-client (2.6.1.pre.beta.1)
|
5
|
+
rake-compiler (~> 1.0)
|
6
|
+
rice (~> 2.1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
diff-lcs (1.3)
|
12
12
|
rake (10.5.0)
|
13
|
-
rake-compiler (1.
|
13
|
+
rake-compiler (1.1.1)
|
14
14
|
rake
|
15
|
-
rice (2.
|
15
|
+
rice (2.2.0)
|
16
16
|
rspec (3.8.0)
|
17
17
|
rspec-core (~> 3.8.0)
|
18
18
|
rspec-expectations (~> 3.8.0)
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
Add this line to your application's Gemfile:
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
gem "pulsar-client", "~> 2.
|
8
|
+
gem "pulsar-client", "~> 2.6.1.pre"
|
9
9
|
```
|
10
10
|
|
11
11
|
And then execute:
|
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
Note #1: You will need libpulsar (for linking) and libpulsar-dev (for
|
20
20
|
C++ client header files, for compiling) installed first. For both, the
|
21
|
-
Gem currently targets version 2.
|
21
|
+
Gem currently targets version 2.6.1. If your libpulsar is older, it will
|
22
22
|
fail to compile. If it is newer, it _might_ compile is not guaranteed.
|
23
23
|
|
24
24
|
Note #2: This is a pre-release version of this Gem. You will need the
|
@@ -30,7 +30,9 @@ the `.pre` suffix in the Gemfile to install it via Bundler.
|
|
30
30
|
Setup and basic `consumer.receive` example:
|
31
31
|
|
32
32
|
```ruby
|
33
|
-
#
|
33
|
+
# use a standard Pulsar client config (see https://github.com/apache/pulsar/blob/master/conf/client.conf)
|
34
|
+
# export PULSAR_CLIENT_CONF=/path/to/your/client/conf/client_conf.conf
|
35
|
+
# OR, if not present have these in your shell with appropriate values
|
34
36
|
# export PULSAR_BROKER_URI=pulsar://your-pulsar-broker:6651
|
35
37
|
# export PULSAR_CERT_PATH=/path/to/your/pulsar-ca.pem
|
36
38
|
# export PULSAR_AUTH_TOKEN=your-auth-token
|
data/Rakefile
CHANGED
data/bin/example-consumer
CHANGED
@@ -23,14 +23,17 @@ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
|
23
23
|
|
24
24
|
require "pulsar/client"
|
25
25
|
|
26
|
-
unless ARGV.size >= 1 && ARGV.size <= 2 &&
|
26
|
+
unless ARGV.size >= 1 && ARGV.size <= 2 && Pulsar::Client.sufficient_environment?
|
27
27
|
puts "Usage: #{__FILE__} <topic> [consumer-name]"
|
28
28
|
puts
|
29
29
|
puts "If not specified, the consumer name defaults to 'example-consumer'."
|
30
30
|
puts
|
31
|
-
puts "
|
32
|
-
puts "
|
33
|
-
puts "
|
31
|
+
puts "If set, PULSAR_CLIENT_CONF is loaded and used as a configuration."
|
32
|
+
puts "Broker URI, TLS settings and the authorization token to use is loaded"
|
33
|
+
puts "from this file."
|
34
|
+
puts "If this variable is not present, the PULSAR_BROKER_URI environment variable"
|
35
|
+
puts "must be set. In this case PULSAR_CERT_PATH and PULSAR_AUTH_TOKEN environment"
|
36
|
+
puts "variables are also recognized."
|
34
37
|
exit 1
|
35
38
|
end
|
36
39
|
|
data/bin/example-producer
CHANGED
@@ -23,16 +23,19 @@ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
|
23
23
|
|
24
24
|
require "pulsar/client"
|
25
25
|
|
26
|
-
unless ARGV.size == 1 &&
|
26
|
+
unless ARGV.size == 1 && Pulsar::Client.sufficient_environment?
|
27
27
|
puts "Usage: #{__FILE__} <topic>"
|
28
28
|
puts
|
29
|
-
puts "
|
30
|
-
puts "
|
31
|
-
puts "
|
29
|
+
puts "If set, PULSAR_CLIENT_CONF is loaded and used as a configuration."
|
30
|
+
puts "Broker URI, TLS settings and the authorization token to use is loaded"
|
31
|
+
puts "from this file."
|
32
|
+
puts "If this variable is not present, the PULSAR_BROKER_URI environment variable"
|
33
|
+
puts "must be set. In this case PULSAR_CERT_PATH and PULSAR_AUTH_TOKEN environment"
|
34
|
+
puts "variables are also recognized."
|
32
35
|
exit 1
|
33
36
|
end
|
34
37
|
|
35
|
-
topic = ARGV
|
38
|
+
topic = ARGV.shift
|
36
39
|
client = Pulsar::Client.from_environment
|
37
40
|
producer = client.create_producer(topic)
|
38
41
|
while data = gets
|
data/ext/bindings/client.cpp
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
#include <ruby/thread.h>
|
5
5
|
|
6
6
|
#include "client.hpp"
|
7
|
+
#include "logger.hpp"
|
7
8
|
#include "util.hpp"
|
8
9
|
|
9
10
|
namespace pulsar_rb {
|
@@ -55,6 +56,25 @@ void ClientConfiguration::setLogConfFilePath(const std::string& path) {
|
|
55
56
|
_config.setLogConfFilePath(path);
|
56
57
|
}
|
57
58
|
|
59
|
+
void ClientConfiguration::setSilentLogging(bool enable) {
|
60
|
+
// The logger can only be set once, so if it's already on we cannot disable it.
|
61
|
+
if (silentLogging) {
|
62
|
+
if (!enable) {
|
63
|
+
throw Rice::Exception(rb_eArgError, "silent_logging can only be set once");
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
if (enable) {
|
68
|
+
silentLogging = true;
|
69
|
+
std::unique_ptr<LoggerFactory> loggerFactory = SilentLoggerFactory::create();
|
70
|
+
_config.setLogger(loggerFactory.release());
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
bool ClientConfiguration::getSilentLogging() {
|
75
|
+
return silentLogging;
|
76
|
+
}
|
77
|
+
|
58
78
|
bool ClientConfiguration::isUseTls() {
|
59
79
|
return _config.isUseTls();
|
60
80
|
}
|
@@ -175,6 +195,8 @@ void bind_client(Module& module) {
|
|
175
195
|
.define_method("concurrent_lookup_requests=", &pulsar_rb::ClientConfiguration::setConcurrentLookupRequest)
|
176
196
|
.define_method("log_conf_file_path", &pulsar_rb::ClientConfiguration::getLogConfFilePath)
|
177
197
|
.define_method("log_conf_file_path=", &pulsar_rb::ClientConfiguration::setLogConfFilePath)
|
198
|
+
.define_method("silent_logging?", &pulsar_rb::ClientConfiguration::getSilentLogging)
|
199
|
+
.define_method("silent_logging=", &pulsar_rb::ClientConfiguration::setSilentLogging)
|
178
200
|
.define_method("use_tls?", &pulsar_rb::ClientConfiguration::isUseTls)
|
179
201
|
.define_method("use_tls=", &pulsar_rb::ClientConfiguration::setUseTls)
|
180
202
|
.define_method("tls_trust_certs_file_path", &pulsar_rb::ClientConfiguration::getTlsTrustCertsFilePath)
|
data/ext/bindings/client.hpp
CHANGED
@@ -13,6 +13,7 @@ namespace pulsar_rb {
|
|
13
13
|
class ClientConfiguration {
|
14
14
|
public:
|
15
15
|
pulsar::ClientConfiguration _config;
|
16
|
+
bool silentLogging = false;
|
16
17
|
ClientConfiguration();
|
17
18
|
|
18
19
|
void setAuthFromToken(const std::string &token);
|
@@ -26,6 +27,8 @@ namespace pulsar_rb {
|
|
26
27
|
void setConcurrentLookupRequest(int n);
|
27
28
|
std::string getLogConfFilePath();
|
28
29
|
void setLogConfFilePath(const std::string& path);
|
30
|
+
void setSilentLogging(bool);
|
31
|
+
bool getSilentLogging();
|
29
32
|
bool isUseTls();
|
30
33
|
void setUseTls(bool enable);
|
31
34
|
std::string getTlsTrustCertsFilePath();
|
data/ext/bindings/consumer.cpp
CHANGED
@@ -16,6 +16,11 @@ typedef struct {
|
|
16
16
|
pulsar::Result result;
|
17
17
|
} consumer_receive_job;
|
18
18
|
|
19
|
+
typedef struct {
|
20
|
+
pulsar::Consumer& consumer;
|
21
|
+
pulsar::Result result;
|
22
|
+
} consumer_close_task;
|
23
|
+
|
19
24
|
void* consumer_receive_nogvl(void* jobPtr) {
|
20
25
|
consumer_receive_job& job = *(consumer_receive_job*)jobPtr;
|
21
26
|
if (job.timeout_ms > 0) {
|
@@ -46,6 +51,18 @@ void Consumer::negative_acknowledge(const Message& message) {
|
|
46
51
|
_consumer.negativeAcknowledge(message._msg);
|
47
52
|
}
|
48
53
|
|
54
|
+
void* consumer_close_worker(void* taskPtr) {
|
55
|
+
consumer_close_task& task = *(consumer_close_task*)taskPtr;
|
56
|
+
task.result = task.consumer.close();
|
57
|
+
return nullptr;
|
58
|
+
}
|
59
|
+
|
60
|
+
void Consumer::close() {
|
61
|
+
consumer_close_task task = { _consumer };
|
62
|
+
rb_thread_call_without_gvl(&consumer_close_worker, &task, RUBY_UBF_IO, nullptr);
|
63
|
+
CheckResult(task.result);
|
64
|
+
}
|
65
|
+
|
49
66
|
}
|
50
67
|
|
51
68
|
using namespace Rice;
|
@@ -56,6 +73,7 @@ void bind_consumer(Module &module) {
|
|
56
73
|
.define_method("receive", &pulsar_rb::Consumer::receive, (Arg("timeout_ms") = 0))
|
57
74
|
.define_method("acknowledge", &pulsar_rb::Consumer::acknowledge)
|
58
75
|
.define_method("negative_acknowledge", &pulsar_rb::Consumer::negative_acknowledge)
|
76
|
+
.define_method("close", &pulsar_rb::Consumer::close)
|
59
77
|
;
|
60
78
|
|
61
79
|
define_enum<pulsar::ConsumerType>("ConsumerType", module)
|
data/ext/bindings/consumer.hpp
CHANGED
data/ext/bindings/extconf.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
#include <pulsar/Logger.h>
|
2
|
+
|
3
|
+
#include "logger.hpp"
|
4
|
+
|
5
|
+
namespace pulsar_rb {
|
6
|
+
|
7
|
+
class SilentLogger : public pulsar::Logger {
|
8
|
+
std::string _logger;
|
9
|
+
|
10
|
+
public:
|
11
|
+
SilentLogger(const std::string &logger) : _logger(logger) {}
|
12
|
+
|
13
|
+
bool isEnabled(Level level) { return false; }
|
14
|
+
void log(Level level, int line, const std::string &message) { }
|
15
|
+
};
|
16
|
+
|
17
|
+
pulsar::Logger *SilentLoggerFactory::getLogger(const std::string& file) { return new SilentLogger(file); }
|
18
|
+
|
19
|
+
std::unique_ptr<pulsar::LoggerFactory> SilentLoggerFactory::create() {
|
20
|
+
return std::unique_ptr<pulsar::LoggerFactory>(new SilentLoggerFactory());
|
21
|
+
}
|
22
|
+
|
23
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#ifndef __PULSAR_RUBY_CLIENT_LOGGER_HPP
|
2
|
+
#define __PULSAR_RUBY_CLIENT_LOGGER_HPP
|
3
|
+
|
4
|
+
#include <pulsar/Logger.h>
|
5
|
+
|
6
|
+
namespace pulsar_rb {
|
7
|
+
|
8
|
+
class SilentLoggerFactory : public pulsar::LoggerFactory {
|
9
|
+
public:
|
10
|
+
pulsar::Logger* getLogger(const std::string& fileName);
|
11
|
+
|
12
|
+
static std::unique_ptr<pulsar::LoggerFactory> create();
|
13
|
+
};
|
14
|
+
|
15
|
+
}
|
16
|
+
|
17
|
+
#endif
|
data/ext/bindings/message.cpp
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
#include "rice/Data_Type.hpp"
|
2
2
|
#include "rice/Constructor.hpp"
|
3
|
+
#include "rice/Exception.hpp"
|
3
4
|
#include <pulsar/Client.h>
|
4
5
|
|
5
6
|
#include "message.hpp"
|
7
|
+
#include "stringmap.hpp"
|
6
8
|
|
7
9
|
namespace pulsar_rb {
|
8
10
|
|
@@ -12,9 +14,32 @@ Rice::String MessageId::toString() {
|
|
12
14
|
return Rice::String(ss.str());
|
13
15
|
}
|
14
16
|
|
15
|
-
Message::Message(const std::string& data) {
|
17
|
+
Message::Message(const std::string& data, Rice::Object arg = Rice::Object()) {
|
16
18
|
pulsar::MessageBuilder mb;
|
17
19
|
mb.setContent(data);
|
20
|
+
|
21
|
+
if (arg && arg.rb_type() != T_NONE) {
|
22
|
+
Rice::Hash opts = Rice::Hash(arg);
|
23
|
+
Rice::Hash::iterator it = opts.begin();
|
24
|
+
Rice::Hash::iterator end = opts.end();
|
25
|
+
std::string key;
|
26
|
+
for (; it != end; ++it) {
|
27
|
+
key = it->key.to_s().str();
|
28
|
+
if (key == "properties"){
|
29
|
+
Rice::Object value = Rice::Object(it->value);
|
30
|
+
if (value.rb_type() != T_NIL) {
|
31
|
+
mb.setProperties(from_ruby<pulsar::StringMap>(value));
|
32
|
+
}
|
33
|
+
} else if (key == "partition_key") {
|
34
|
+
mb.setPartitionKey(Rice::Object(it->value).to_s().str());
|
35
|
+
} else if (key == "ordering_key") {
|
36
|
+
mb.setOrderingKey(Rice::Object(it->value).to_s().str());
|
37
|
+
} else {
|
38
|
+
throw Rice::Exception(rb_eArgError, "Unknown keyword argument: %s", key.c_str());
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
18
43
|
_msg = mb.build();
|
19
44
|
}
|
20
45
|
|
@@ -28,6 +53,18 @@ MessageId::ptr Message::getMessageId() {
|
|
28
53
|
return MessageId::ptr(new MessageId(messageId));
|
29
54
|
}
|
30
55
|
|
56
|
+
Rice::Hash Message::getProperties() {
|
57
|
+
return to_ruby(_msg.getProperties());
|
58
|
+
}
|
59
|
+
|
60
|
+
Rice::String Message::getPartitionKey() {
|
61
|
+
return to_ruby(_msg.getPartitionKey());
|
62
|
+
}
|
63
|
+
|
64
|
+
Rice::String Message::getOrderingKey() {
|
65
|
+
return to_ruby(_msg.getOrderingKey());
|
66
|
+
}
|
67
|
+
|
31
68
|
}
|
32
69
|
|
33
70
|
using namespace Rice;
|
@@ -40,8 +77,12 @@ void bind_message(Module& module) {
|
|
40
77
|
|
41
78
|
define_class_under<pulsar_rb::Message>(module, "Message")
|
42
79
|
.define_constructor(Constructor<pulsar_rb::Message, const pulsar::Message&>())
|
43
|
-
.define_constructor(Constructor<pulsar_rb::Message, const std::string
|
80
|
+
.define_constructor(Constructor<pulsar_rb::Message, const std::string&, const Rice::Object>(),
|
81
|
+
(Rice::Arg("data"), Rice::Arg("options") = Rice::Object()))
|
44
82
|
.define_method("data", &pulsar_rb::Message::getData)
|
45
83
|
.define_method("message_id", &pulsar_rb::Message::getMessageId)
|
84
|
+
.define_method("properties", &pulsar_rb::Message::getProperties)
|
85
|
+
.define_method("partition_key", &pulsar_rb::Message::getPartitionKey)
|
86
|
+
.define_method("ordering_key", &pulsar_rb::Message::getOrderingKey)
|
46
87
|
;
|
47
88
|
}
|
data/ext/bindings/message.hpp
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#ifndef __PULSAR_RUBY_CLIENT_MESSAGE_HPP
|
2
2
|
#define __PULSAR_RUBY_CLIENT_MESSAGE_HPP
|
3
3
|
|
4
|
+
#include "rice/Hash.hpp"
|
4
5
|
#include "rice/Module.hpp"
|
5
6
|
#include "rice/String.hpp"
|
6
7
|
#include "rice/Data_Object.hpp"
|
@@ -21,10 +22,13 @@ namespace pulsar_rb {
|
|
21
22
|
public:
|
22
23
|
pulsar::Message _msg;
|
23
24
|
Message(const pulsar::Message& msg) : _msg(msg) {};
|
24
|
-
Message(const std::string& data);
|
25
|
+
Message(const std::string& data, Rice::Object opts);
|
25
26
|
|
26
27
|
Rice::String getData();
|
27
28
|
MessageId::ptr getMessageId();
|
29
|
+
Rice::Hash getProperties();
|
30
|
+
Rice::String getPartitionKey();
|
31
|
+
Rice::String getOrderingKey();
|
28
32
|
|
29
33
|
typedef Rice::Data_Object<Message> ptr;
|
30
34
|
};
|
data/ext/bindings/producer.cpp
CHANGED
@@ -14,6 +14,11 @@ typedef struct {
|
|
14
14
|
pulsar::Result result;
|
15
15
|
} producer_send_task;
|
16
16
|
|
17
|
+
typedef struct {
|
18
|
+
pulsar::Producer& producer;
|
19
|
+
pulsar::Result result;
|
20
|
+
} producer_close_task;
|
21
|
+
|
17
22
|
void* producer_send_worker(void* taskPtr) {
|
18
23
|
producer_send_task& task = *(producer_send_task*)taskPtr;
|
19
24
|
task.result = task.producer.send(task.message);
|
@@ -26,6 +31,18 @@ void Producer::send(const Message& message) {
|
|
26
31
|
CheckResult(task.result);
|
27
32
|
}
|
28
33
|
|
34
|
+
void* producer_close_worker(void* taskPtr) {
|
35
|
+
producer_close_task& task = *(producer_close_task*)taskPtr;
|
36
|
+
task.result = task.producer.close();
|
37
|
+
return nullptr;
|
38
|
+
}
|
39
|
+
|
40
|
+
void Producer::close() {
|
41
|
+
producer_close_task task = { _producer };
|
42
|
+
rb_thread_call_without_gvl(&producer_close_worker, &task, RUBY_UBF_IO, nullptr);
|
43
|
+
CheckResult(task.result);
|
44
|
+
}
|
45
|
+
|
29
46
|
}
|
30
47
|
|
31
48
|
using namespace Rice;
|
@@ -34,6 +51,7 @@ void bind_producer(Module& module) {
|
|
34
51
|
define_class_under<pulsar_rb::Producer>(module, "Producer")
|
35
52
|
.define_constructor(Constructor<pulsar_rb::Producer>())
|
36
53
|
.define_method("send", &pulsar_rb::Producer::send)
|
54
|
+
.define_method("close", &pulsar_rb::Producer::close)
|
37
55
|
;
|
38
56
|
|
39
57
|
define_class_under<pulsar_rb::ProducerConfiguration>(module, "ProducerConfiguration")
|
data/ext/bindings/producer.hpp
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
#include "rice/Hash.hpp"
|
2
|
+
|
3
|
+
#include "stringmap.hpp"
|
4
|
+
|
5
|
+
template<>
|
6
|
+
pulsar::StringMap from_ruby<pulsar::StringMap>(Rice::Object o)
|
7
|
+
{
|
8
|
+
Rice::Hash h(o);
|
9
|
+
pulsar::StringMap m;
|
10
|
+
Rice::Hash::iterator it = h.begin();
|
11
|
+
Rice::Hash::iterator end = h.end();
|
12
|
+
for(; it != end; ++it) {
|
13
|
+
m[it->key.to_s().str()] = Rice::Object(it->value).to_s().str();
|
14
|
+
}
|
15
|
+
return m;
|
16
|
+
}
|
17
|
+
|
18
|
+
template<>
|
19
|
+
Rice::Object to_ruby<pulsar::StringMap>(pulsar::StringMap const & m)
|
20
|
+
{
|
21
|
+
Rice::Hash h = Rice::Hash();
|
22
|
+
|
23
|
+
pulsar::StringMap::const_iterator it = m.begin();
|
24
|
+
pulsar::StringMap::const_iterator end = m.end();
|
25
|
+
for(; it != end; ++it) {
|
26
|
+
h[Rice::String(it->first)] = Rice::String(it->second);
|
27
|
+
}
|
28
|
+
|
29
|
+
// Be clear that calling hash[x]= will have no effect.
|
30
|
+
h.freeze();
|
31
|
+
|
32
|
+
return h;
|
33
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#ifndef __PULSAR_RUBY_CLIENT_STRINGMAP_HPP
|
2
|
+
#define __PULSAR_RUBY_CLIENT_STRINGMAP_HPP
|
3
|
+
|
4
|
+
#include "rice/Object.hpp"
|
5
|
+
#include <pulsar/Client.h>
|
6
|
+
|
7
|
+
template<>
|
8
|
+
pulsar::StringMap from_ruby<pulsar::StringMap>(Rice::Object o);
|
9
|
+
|
10
|
+
template<>
|
11
|
+
Rice::Object to_ruby<pulsar::StringMap>(pulsar::StringMap const & m);
|
12
|
+
|
13
|
+
#endif
|
data/ext/bindings/util.cpp
CHANGED
@@ -5,19 +5,179 @@
|
|
5
5
|
|
6
6
|
using namespace Rice;
|
7
7
|
|
8
|
+
// Result enum found in pulsar-*/pulsar-client-cpp/include/pulsar/Result.h
|
9
|
+
|
8
10
|
VALUE rb_ePulsarError = Qnil;
|
11
|
+
VALUE rb_ePulsarError_UnknownError = Qnil;
|
12
|
+
VALUE rb_ePulsarError_InvalidConfiguration = Qnil;
|
9
13
|
VALUE rb_ePulsarError_Timeout = Qnil;
|
14
|
+
VALUE rb_ePulsarError_LookupError = Qnil;
|
15
|
+
VALUE rb_ePulsarError_ConnectError = Qnil;
|
16
|
+
VALUE rb_ePulsarError_ReadError = Qnil;
|
17
|
+
VALUE rb_ePulsarError_AuthenticationError = Qnil;
|
18
|
+
VALUE rb_ePulsarError_AuthorizationError = Qnil;
|
19
|
+
VALUE rb_ePulsarError_ErrorGettingAuthenticationData = Qnil;
|
20
|
+
VALUE rb_ePulsarError_BrokerMetadataError = Qnil;
|
21
|
+
VALUE rb_ePulsarError_BrokerPersistenceError = Qnil;
|
22
|
+
VALUE rb_ePulsarError_ChecksumError = Qnil;
|
23
|
+
VALUE rb_ePulsarError_ConsumerBusy = Qnil;
|
24
|
+
VALUE rb_ePulsarError_NotConnected = Qnil;
|
25
|
+
VALUE rb_ePulsarError_AlreadyClosed = Qnil;
|
26
|
+
VALUE rb_ePulsarError_InvalidMessage = Qnil;
|
27
|
+
VALUE rb_ePulsarError_ConsumerNotInitialized = Qnil;
|
28
|
+
VALUE rb_ePulsarError_ProducerNotInitialized = Qnil;
|
29
|
+
VALUE rb_ePulsarError_ProducerBusy = Qnil;
|
30
|
+
VALUE rb_ePulsarError_TooManyLookupRequestException = Qnil;
|
31
|
+
VALUE rb_ePulsarError_InvalidTopicName = Qnil;
|
32
|
+
VALUE rb_ePulsarError_InvalidUrl = Qnil;
|
33
|
+
VALUE rb_ePulsarError_ServiceUnitNotReady = Qnil;
|
34
|
+
VALUE rb_ePulsarError_OperationNotSupported = Qnil;
|
35
|
+
VALUE rb_ePulsarError_ProducerBlockedQuotaExceededError = Qnil;
|
36
|
+
VALUE rb_ePulsarError_ProducerBlockedQuotaExceededException = Qnil;
|
37
|
+
VALUE rb_ePulsarError_ProducerQueueIsFull = Qnil;
|
38
|
+
VALUE rb_ePulsarError_MessageTooBig = Qnil;
|
39
|
+
VALUE rb_ePulsarError_TopicNotFound = Qnil;
|
40
|
+
VALUE rb_ePulsarError_SubscriptionNotFound = Qnil;
|
41
|
+
VALUE rb_ePulsarError_ConsumerNotFound = Qnil;
|
42
|
+
VALUE rb_ePulsarError_UnsupportedVersionError = Qnil;
|
43
|
+
VALUE rb_ePulsarError_TopicTerminated = Qnil;
|
44
|
+
VALUE rb_ePulsarError_CryptoError = Qnil;
|
45
|
+
VALUE rb_ePulsarError_IncompatibleSchema = Qnil;
|
46
|
+
VALUE rb_ePulsarError_ConsumerAssignError = Qnil;
|
47
|
+
VALUE rb_ePulsarError_CumulativeAcknowledgementNotAllowedError = Qnil;
|
48
|
+
VALUE rb_ePulsarError_TransactionCoordinatorNotFoundError = Qnil;
|
49
|
+
VALUE rb_ePulsarError_InvalidTxnStatusError = Qnil;
|
50
|
+
VALUE rb_ePulsarError_NotAllowedError = Qnil;
|
10
51
|
|
11
52
|
void bind_errors(Module &module) {
|
12
53
|
rb_ePulsarError = rb_define_class_under(module.value(), "Error", rb_eStandardError);
|
54
|
+
rb_ePulsarError_UnknownError = rb_define_class_under(rb_ePulsarError, "UnknownError", rb_ePulsarError);
|
55
|
+
rb_ePulsarError_InvalidConfiguration = rb_define_class_under(rb_ePulsarError, "InvalidConfiguration", rb_ePulsarError);
|
13
56
|
rb_ePulsarError_Timeout = rb_define_class_under(rb_ePulsarError, "Timeout", rb_ePulsarError);
|
57
|
+
rb_ePulsarError_LookupError = rb_define_class_under(rb_ePulsarError, "LookupError", rb_ePulsarError);
|
58
|
+
rb_ePulsarError_ConnectError = rb_define_class_under(rb_ePulsarError, "ConnectError", rb_ePulsarError);
|
59
|
+
rb_ePulsarError_ReadError = rb_define_class_under(rb_ePulsarError, "ReadError", rb_ePulsarError);
|
60
|
+
rb_ePulsarError_AuthenticationError = rb_define_class_under(rb_ePulsarError, "AuthenticationError", rb_ePulsarError);
|
61
|
+
rb_ePulsarError_AuthorizationError = rb_define_class_under(rb_ePulsarError, "AuthorizationError", rb_ePulsarError);
|
62
|
+
rb_ePulsarError_ErrorGettingAuthenticationData = rb_define_class_under(rb_ePulsarError, "ErrorGettingAuthenticationData", rb_ePulsarError);
|
63
|
+
rb_ePulsarError_BrokerMetadataError = rb_define_class_under(rb_ePulsarError, "BrokerMetadataError", rb_ePulsarError);
|
64
|
+
rb_ePulsarError_BrokerPersistenceError = rb_define_class_under(rb_ePulsarError, "BrokerPersistenceError", rb_ePulsarError);
|
65
|
+
rb_ePulsarError_ChecksumError = rb_define_class_under(rb_ePulsarError, "ChecksumError", rb_ePulsarError);
|
66
|
+
rb_ePulsarError_ConsumerBusy = rb_define_class_under(rb_ePulsarError, "ConsumerBusy", rb_ePulsarError);
|
67
|
+
rb_ePulsarError_NotConnected = rb_define_class_under(rb_ePulsarError, "NotConnected", rb_ePulsarError);
|
68
|
+
rb_ePulsarError_AlreadyClosed = rb_define_class_under(rb_ePulsarError, "AlreadyClosed", rb_ePulsarError);
|
69
|
+
rb_ePulsarError_InvalidMessage = rb_define_class_under(rb_ePulsarError, "InvalidMessage", rb_ePulsarError);
|
70
|
+
rb_ePulsarError_ConsumerNotInitialized = rb_define_class_under(rb_ePulsarError, "ConsumerNotInitialized", rb_ePulsarError);
|
71
|
+
rb_ePulsarError_ProducerNotInitialized = rb_define_class_under(rb_ePulsarError, "ProducerNotInitialized", rb_ePulsarError);
|
72
|
+
rb_ePulsarError_ProducerBusy = rb_define_class_under(rb_ePulsarError, "ProducerBusy", rb_ePulsarError);
|
73
|
+
rb_ePulsarError_TooManyLookupRequestException = rb_define_class_under(rb_ePulsarError, "TooManyLookupRequestException", rb_ePulsarError);
|
74
|
+
rb_ePulsarError_InvalidTopicName = rb_define_class_under(rb_ePulsarError, "InvalidTopicName", rb_ePulsarError);
|
75
|
+
rb_ePulsarError_InvalidUrl = rb_define_class_under(rb_ePulsarError, "InvalidUrl", rb_ePulsarError);
|
76
|
+
rb_ePulsarError_ServiceUnitNotReady = rb_define_class_under(rb_ePulsarError, "ServiceUnitNotReady", rb_ePulsarError);
|
77
|
+
rb_ePulsarError_OperationNotSupported = rb_define_class_under(rb_ePulsarError, "OperationNotSupported", rb_ePulsarError);
|
78
|
+
rb_ePulsarError_ProducerBlockedQuotaExceededError = rb_define_class_under(rb_ePulsarError, "ProducerBlockedQuotaExceededError", rb_ePulsarError);
|
79
|
+
rb_ePulsarError_ProducerBlockedQuotaExceededException = rb_define_class_under(rb_ePulsarError, "ProducerBlockedQuotaExceededException", rb_ePulsarError);
|
80
|
+
rb_ePulsarError_ProducerQueueIsFull = rb_define_class_under(rb_ePulsarError, "ProducerQueueIsFull", rb_ePulsarError);
|
81
|
+
rb_ePulsarError_MessageTooBig = rb_define_class_under(rb_ePulsarError, "MessageTooBig", rb_ePulsarError);
|
82
|
+
rb_ePulsarError_TopicNotFound = rb_define_class_under(rb_ePulsarError, "TopicNotFound", rb_ePulsarError);
|
83
|
+
rb_ePulsarError_SubscriptionNotFound = rb_define_class_under(rb_ePulsarError, "SubscriptionNotFound", rb_ePulsarError);
|
84
|
+
rb_ePulsarError_ConsumerNotFound = rb_define_class_under(rb_ePulsarError, "ConsumerNotFound", rb_ePulsarError);
|
85
|
+
rb_ePulsarError_UnsupportedVersionError = rb_define_class_under(rb_ePulsarError, "UnsupportedVersionError", rb_ePulsarError);
|
86
|
+
rb_ePulsarError_TopicTerminated = rb_define_class_under(rb_ePulsarError, "TopicTerminated", rb_ePulsarError);
|
87
|
+
rb_ePulsarError_CryptoError = rb_define_class_under(rb_ePulsarError, "CryptoError", rb_ePulsarError);
|
88
|
+
rb_ePulsarError_IncompatibleSchema = rb_define_class_under(rb_ePulsarError, "IncompatibleSchema", rb_ePulsarError);
|
89
|
+
rb_ePulsarError_ConsumerAssignError = rb_define_class_under(rb_ePulsarError, "ConsumerAssignError", rb_ePulsarError);
|
90
|
+
rb_ePulsarError_CumulativeAcknowledgementNotAllowedError = rb_define_class_under(rb_ePulsarError, "CumulativeAcknowledgementNotAllowedError", rb_ePulsarError);
|
91
|
+
rb_ePulsarError_TransactionCoordinatorNotFoundError = rb_define_class_under(rb_ePulsarError, "TransactionCoordinatorNotFoundError", rb_ePulsarError);
|
92
|
+
rb_ePulsarError_InvalidTxnStatusError = rb_define_class_under(rb_ePulsarError, "InvalidTxnStatusError", rb_ePulsarError);
|
93
|
+
rb_ePulsarError_NotAllowedError = rb_define_class_under(rb_ePulsarError, "NotAllowedError", rb_ePulsarError);
|
14
94
|
}
|
15
95
|
|
16
96
|
void CheckResult(pulsar::Result res) {
|
17
|
-
if (res
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
97
|
+
if (res != pulsar::ResultOk) {
|
98
|
+
switch(res) {
|
99
|
+
case pulsar::ResultUnknownError:
|
100
|
+
throw Exception(rb_ePulsarError_UnknownError, "Unknown error happened on broker"); break;
|
101
|
+
case pulsar::ResultInvalidConfiguration:
|
102
|
+
throw Exception(rb_ePulsarError_InvalidConfiguration, "Invalid configuration"); break;
|
103
|
+
case pulsar::ResultTimeout:
|
104
|
+
throw Exception(rb_ePulsarError_Timeout, "Operation timed out"); break;
|
105
|
+
case pulsar::ResultLookupError:
|
106
|
+
throw Exception(rb_ePulsarError_LookupError, "Broker lookup failed"); break;
|
107
|
+
case pulsar::ResultConnectError:
|
108
|
+
throw Exception(rb_ePulsarError_ConnectError, "Failed to connect to broker"); break;
|
109
|
+
case pulsar::ResultReadError:
|
110
|
+
throw Exception(rb_ePulsarError_ReadError, "Failed to read from socket"); break;
|
111
|
+
case pulsar::ResultAuthenticationError:
|
112
|
+
throw Exception(rb_ePulsarError_AuthenticationError, "Authentication failed on broker"); break;
|
113
|
+
case pulsar::ResultAuthorizationError:
|
114
|
+
throw Exception(rb_ePulsarError_AuthorizationError, "Client is not authorized to create producer/consumer"); break;
|
115
|
+
case pulsar::ResultErrorGettingAuthenticationData:
|
116
|
+
throw Exception(rb_ePulsarError_ErrorGettingAuthenticationData, "Client cannot find authorization data"); break;
|
117
|
+
case pulsar::ResultBrokerMetadataError:
|
118
|
+
throw Exception(rb_ePulsarError_BrokerMetadataError, "Broker failed in updating metadata"); break;
|
119
|
+
case pulsar::ResultBrokerPersistenceError:
|
120
|
+
throw Exception(rb_ePulsarError_BrokerPersistenceError, "Broker failed to persist entry"); break;
|
121
|
+
case pulsar::ResultChecksumError:
|
122
|
+
throw Exception(rb_ePulsarError_ChecksumError, "Corrupt message checksum failure"); break;
|
123
|
+
case pulsar::ResultConsumerBusy:
|
124
|
+
throw Exception(rb_ePulsarError_ConsumerBusy, "Exclusive consumer is already connected"); break;
|
125
|
+
case pulsar::ResultNotConnected:
|
126
|
+
throw Exception(rb_ePulsarError_NotConnected, "Producer/Consumer is not currently connected to broker"); break;
|
127
|
+
case pulsar::ResultAlreadyClosed:
|
128
|
+
throw Exception(rb_ePulsarError_AlreadyClosed, "Producer/Consumer is already closed and not accepting any operation"); break;
|
129
|
+
case pulsar::ResultInvalidMessage:
|
130
|
+
throw Exception(rb_ePulsarError_InvalidMessage, "Error in publishing an already used message"); break;
|
131
|
+
case pulsar::ResultConsumerNotInitialized:
|
132
|
+
throw Exception(rb_ePulsarError_ConsumerNotInitialized, "Consumer is not initialized"); break;
|
133
|
+
case pulsar::ResultProducerNotInitialized:
|
134
|
+
throw Exception(rb_ePulsarError_ProducerNotInitialized, "Producer is not initialized"); break;
|
135
|
+
case pulsar::ResultProducerBusy:
|
136
|
+
throw Exception(rb_ePulsarError_ProducerBusy, "Producer with same name is already connected"); break;
|
137
|
+
case pulsar::ResultTooManyLookupRequestException:
|
138
|
+
throw Exception(rb_ePulsarError_TooManyLookupRequestException, "Too Many concurrent LookupRequest"); break;
|
139
|
+
case pulsar::ResultInvalidTopicName:
|
140
|
+
throw Exception(rb_ePulsarError_InvalidTopicName, "Invalid topic name"); break;
|
141
|
+
case pulsar::ResultInvalidUrl:
|
142
|
+
throw Exception(rb_ePulsarError_InvalidUrl, "Client Initialized with Invalid Broker Url (VIP Url passed to Client Constructor)"); break;
|
143
|
+
case pulsar::ResultServiceUnitNotReady:
|
144
|
+
throw Exception(rb_ePulsarError_ServiceUnitNotReady, "Service Unit unloaded between client did lookup and producer/consumer got created"); break;
|
145
|
+
case pulsar::ResultOperationNotSupported:
|
146
|
+
throw Exception(rb_ePulsarError_OperationNotSupported, "Operation not supported"); break;
|
147
|
+
case pulsar::ResultProducerBlockedQuotaExceededError:
|
148
|
+
throw Exception(rb_ePulsarError_ProducerBlockedQuotaExceededError, "Producer is blocked"); break;
|
149
|
+
case pulsar::ResultProducerBlockedQuotaExceededException:
|
150
|
+
throw Exception(rb_ePulsarError_ProducerBlockedQuotaExceededException, "Producer is getting exception"); break;
|
151
|
+
case pulsar::ResultProducerQueueIsFull:
|
152
|
+
throw Exception(rb_ePulsarError_ProducerQueueIsFull, "Producer queue is full"); break;
|
153
|
+
case pulsar::ResultMessageTooBig:
|
154
|
+
throw Exception(rb_ePulsarError_MessageTooBig, "Trying to send a messages exceeding the max size"); break;
|
155
|
+
case pulsar::ResultTopicNotFound:
|
156
|
+
throw Exception(rb_ePulsarError_TopicNotFound, "Topic not found"); break;
|
157
|
+
case pulsar::ResultSubscriptionNotFound:
|
158
|
+
throw Exception(rb_ePulsarError_SubscriptionNotFound, "Subscription not found"); break;
|
159
|
+
case pulsar::ResultConsumerNotFound:
|
160
|
+
throw Exception(rb_ePulsarError_ConsumerNotFound, "Consumer not found"); break;
|
161
|
+
case pulsar::ResultUnsupportedVersionError:
|
162
|
+
throw Exception(rb_ePulsarError_UnsupportedVersionError, "Error when an older client/version doesn't support a required feature"); break;
|
163
|
+
case pulsar::ResultTopicTerminated:
|
164
|
+
throw Exception(rb_ePulsarError_TopicTerminated, "Topic was already terminated"); break;
|
165
|
+
case pulsar::ResultCryptoError:
|
166
|
+
throw Exception(rb_ePulsarError_CryptoError, "Error when crypto operation fails"); break;
|
167
|
+
case pulsar::ResultIncompatibleSchema:
|
168
|
+
throw Exception(rb_ePulsarError_IncompatibleSchema, "Specified schema is incompatible with the topic's schema"); break;
|
169
|
+
case pulsar::ResultConsumerAssignError:
|
170
|
+
throw Exception(rb_ePulsarError_ConsumerAssignError, "Error when a new consumer connected but can't assign messages to this consumer"); break;
|
171
|
+
case pulsar::ResultCumulativeAcknowledgementNotAllowedError:
|
172
|
+
throw Exception(rb_ePulsarError_CumulativeAcknowledgementNotAllowedError, "Not allowed to call cumulativeAcknowledgement in Shared and Key_Shared subscription mode"); break;
|
173
|
+
case pulsar::ResultTransactionCoordinatorNotFoundError:
|
174
|
+
throw Exception(rb_ePulsarError_TransactionCoordinatorNotFoundError, "Transaction coordinator not found"); break;
|
175
|
+
case pulsar::ResultInvalidTxnStatusError:
|
176
|
+
throw Exception(rb_ePulsarError_InvalidTxnStatusError, "Invalid txn status error"); break;
|
177
|
+
case pulsar::ResultNotAllowedError:
|
178
|
+
throw Exception(rb_ePulsarError_NotAllowedError, "Not allowed"); break;
|
179
|
+
default:
|
180
|
+
throw Exception(rb_ePulsarError, "unexpected pulsar exception: %d", res);
|
181
|
+
}
|
22
182
|
}
|
23
183
|
}
|
data/lib/pulsar/client.rb
CHANGED
@@ -52,8 +52,8 @@ module Pulsar
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def self.from_environment(config={})
|
55
|
-
broker_uri = config[:broker_uri] || ENV['PULSAR_BROKER_URI']
|
56
55
|
config = Pulsar::ClientConfiguration.from_environment(config)
|
56
|
+
broker_uri = config[:broker_uri] || ENV['PULSAR_BROKER_URI']
|
57
57
|
new(broker_uri, config)
|
58
58
|
end
|
59
59
|
end
|
@@ -21,6 +21,10 @@ require 'pulsar/bindings'
|
|
21
21
|
|
22
22
|
module Pulsar
|
23
23
|
class ClientConfiguration
|
24
|
+
AUTH_TOKEN_PLUGIN_NAME = 'org.apache.pulsar.client.impl.auth.AuthenticationToken'.freeze
|
25
|
+
CLIENT_CONF_KEY_VALUE_SEPARATOR = ': '
|
26
|
+
FILE_URL_PREFIX = 'file://'.freeze
|
27
|
+
|
24
28
|
def self.from(config)
|
25
29
|
case config
|
26
30
|
when self then config # already a config object
|
@@ -30,29 +34,99 @@ module Pulsar
|
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
# Creates a client configuration from a custom and environment configuration
|
38
|
+
# (the environment configuration defaults to OS's ENV)
|
39
|
+
def self.from_environment(config={}, environment=ENV.to_h)
|
40
|
+
environment_config = {}
|
41
|
+
if environment.has_key?('PULSAR_CERT_PATH')
|
42
|
+
environment_config[:use_tls] = true
|
43
|
+
environment_config[:tls_allow_insecure_connection] = false
|
44
|
+
environment_config[:tls_validate_hostname] = false
|
45
|
+
environment_config[:tls_trust_certs_file_path] = environment['PULSAR_CERT_PATH']
|
46
|
+
end
|
47
|
+
if environment.has_key?('PULSAR_AUTH_TOKEN')
|
48
|
+
environment_config[:authentication_token] = environment['PULSAR_AUTH_TOKEN']
|
49
|
+
end
|
50
|
+
if environment.has_key?('PULSAR_CLIENT_CONF')
|
51
|
+
environment_config.merge!(read_from_client_conf(environment['PULSAR_CLIENT_CONF']))
|
52
|
+
end
|
53
|
+
self.from(environment_config.merge(config))
|
54
|
+
end
|
55
|
+
|
56
|
+
# Load configuration from PULSAR_CLIENT_CONF
|
57
|
+
# refer to (see https://github.com/apache/pulsar/blob/master/conf/client.conf)
|
58
|
+
def self.read_from_client_conf(pulsar_client_conf_file)
|
59
|
+
client_config = {}
|
60
|
+
# Read the client config as a Ruby Hashmap
|
61
|
+
pulsar_config = read_config(pulsar_client_conf_file)
|
62
|
+
# Attempt to read as many configuration as possible from the client configuration
|
63
|
+
|
64
|
+
# If a TLS certificate had been given, use it
|
65
|
+
if pulsar_config.has_key? 'tlsTrustCertsFilePath'
|
66
|
+
client_config[:use_tls] = true
|
67
|
+
client_config[:tls_trust_certs_file_path] = pulsar_config['tlsTrustCertsFilePath']
|
40
68
|
end
|
41
|
-
|
42
|
-
|
69
|
+
# If 'TLS enable hostname verification' is false, then switch it off in config
|
70
|
+
if (pulsar_config.has_key? 'tlsEnableHostnameVerification') &&
|
71
|
+
pulsar_config['tlsEnableHostnameVerification'].eql?('false')
|
72
|
+
client_config[:tls_validate_hostname] = false
|
43
73
|
end
|
44
|
-
|
74
|
+
# If 'TLS allow insecure connection' is false, then switch it off in config
|
75
|
+
if (pulsar_config.has_key? 'tlsAllowInsecureConnection') &&
|
76
|
+
pulsar_config['tlsAllowInsecureConnection'].eql?('false')
|
77
|
+
client_config[:tls_allow_insecure_connection] = false
|
78
|
+
end
|
79
|
+
# If token-based authentication is used, load the token
|
80
|
+
# Currently only loading from files is supported
|
81
|
+
if (pulsar_config['authPlugin'].eql? AUTH_TOKEN_PLUGIN_NAME) &&
|
82
|
+
pulsar_config['authParams'].start_with?(FILE_URL_PREFIX)
|
83
|
+
# read the first line from the token file
|
84
|
+
token_file = pulsar_config['authParams'].gsub(FILE_URL_PREFIX, '')
|
85
|
+
begin
|
86
|
+
token_file_lines = File.readlines(token_file)
|
87
|
+
# store the token to the config
|
88
|
+
client_config[:authentication_token] = token_file_lines[0]
|
89
|
+
rescue Errno::ENOENT => e
|
90
|
+
warn("Could not load token file '#{token_file}'. Exception was #{e}.")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
# If we have a broker service URI, use it
|
94
|
+
client_config[:broker_uri] = pulsar_config['brokerServiceUrl'] if pulsar_config.has_key? 'brokerServiceUrl'
|
95
|
+
client_config
|
96
|
+
end
|
97
|
+
|
98
|
+
# read Pulsar client configuration as a Hashmap from a client configuration file
|
99
|
+
def self.read_config(pulsar_config_file)
|
100
|
+
result = []
|
101
|
+
begin
|
102
|
+
config_file_content = File.readlines(pulsar_config_file)
|
103
|
+
result = config_file_content.map do |line|
|
104
|
+
key_value = line.split(CLIENT_CONF_KEY_VALUE_SEPARATOR, 2)
|
105
|
+
[key_value[0], key_value[1].strip]
|
106
|
+
end
|
107
|
+
rescue Errno::ENOENT => e
|
108
|
+
warn("Could not load client config file '#{pulsar_config_file}'. Exception was #{e}.")
|
109
|
+
end
|
110
|
+
return result.to_h
|
45
111
|
end
|
46
112
|
|
47
113
|
module RubySideTweaks
|
48
114
|
def initialize(config={})
|
49
115
|
super()
|
116
|
+
# store client configuration inside class
|
117
|
+
@config = config
|
50
118
|
populate(config)
|
51
119
|
end
|
52
120
|
end
|
53
121
|
|
54
122
|
prepend RubySideTweaks
|
55
123
|
|
124
|
+
# serve the client configuration to peer objects
|
125
|
+
# (eg. we need to configure the 'broker URI' in a different way)
|
126
|
+
def [](key)
|
127
|
+
@config[key]
|
128
|
+
end
|
129
|
+
|
56
130
|
def populate(config={})
|
57
131
|
populate_one(config, :authentication_token)
|
58
132
|
populate_one(config, :operation_timeout_seconds)
|
@@ -60,6 +134,7 @@ module Pulsar
|
|
60
134
|
populate_one(config, :message_listener_threads)
|
61
135
|
populate_one(config, :concurrent_lookup_requests)
|
62
136
|
populate_one(config, :log_conf_file_path)
|
137
|
+
populate_one(config, :silent_logging)
|
63
138
|
populate_one(config, :use_tls)
|
64
139
|
populate_one(config, :tls_trust_certs_file_path)
|
65
140
|
populate_one(config, :tls_allow_insecure_connection)
|
@@ -36,7 +36,7 @@ module Pulsar
|
|
36
36
|
module RubySideTweaks
|
37
37
|
def initialize(config={})
|
38
38
|
super()
|
39
|
-
self.consumer_type = config
|
39
|
+
self.consumer_type = config[:consumer_type] if config.has_key?(:consumer_type)
|
40
40
|
end
|
41
41
|
|
42
42
|
def consumer_type
|
data/lib/pulsar/producer.rb
CHANGED
@@ -22,10 +22,13 @@ require 'pulsar/bindings'
|
|
22
22
|
module Pulsar
|
23
23
|
class Producer
|
24
24
|
module RubySideTweaks
|
25
|
-
def send(message)
|
25
|
+
def send(message, **opts)
|
26
26
|
unless message.is_a?(Pulsar::Message)
|
27
|
-
message = Pulsar::Message.new(message)
|
27
|
+
message = Pulsar::Message.new(message, opts)
|
28
|
+
else
|
29
|
+
warn "Ignoring options (#{opts.keys.join(", ")}) since message is already a Pulsar::Message" unless opts.empty?
|
28
30
|
end
|
31
|
+
|
29
32
|
super(message)
|
30
33
|
end
|
31
34
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pulsar-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.1.pre.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Fugal
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-10-03 00:00:00.000000000 Z
|
@@ -109,10 +109,14 @@ files:
|
|
109
109
|
- ext/bindings/consumer.cpp
|
110
110
|
- ext/bindings/consumer.hpp
|
111
111
|
- ext/bindings/extconf.rb
|
112
|
+
- ext/bindings/logger.cpp
|
113
|
+
- ext/bindings/logger.hpp
|
112
114
|
- ext/bindings/message.cpp
|
113
115
|
- ext/bindings/message.hpp
|
114
116
|
- ext/bindings/producer.cpp
|
115
117
|
- ext/bindings/producer.hpp
|
118
|
+
- ext/bindings/stringmap.cpp
|
119
|
+
- ext/bindings/stringmap.hpp
|
116
120
|
- ext/bindings/util.cpp
|
117
121
|
- ext/bindings/util.hpp
|
118
122
|
- lib/pulsar/client.rb
|
@@ -126,7 +130,7 @@ homepage: https://github.com/instructure/pulsar-client-ruby
|
|
126
130
|
licenses:
|
127
131
|
- Apache-2.0
|
128
132
|
metadata: {}
|
129
|
-
post_install_message:
|
133
|
+
post_install_message:
|
130
134
|
rdoc_options: []
|
131
135
|
require_paths:
|
132
136
|
- lib
|
@@ -141,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
145
|
- !ruby/object:Gem::Version
|
142
146
|
version: 1.3.1
|
143
147
|
requirements: []
|
144
|
-
|
145
|
-
|
146
|
-
signing_key:
|
148
|
+
rubygems_version: 3.1.2
|
149
|
+
signing_key:
|
147
150
|
specification_version: 4
|
148
151
|
summary: Apache Pulsar Ruby Client
|
149
152
|
test_files: []
|