pulsar-client 2.4.1.pre.beta.1 → 2.4.1.pre.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -4
- data/ext/bindings/bindings.cpp +2 -0
- data/ext/bindings/consumer.cpp +11 -6
- data/ext/bindings/consumer.hpp +1 -1
- data/ext/bindings/util.cpp +16 -4
- data/ext/bindings/util.hpp +3 -6
- data/lib/pulsar/client/version.rb +1 -1
- data/lib/pulsar/client.rb +4 -2
- data/lib/pulsar/consumer.rb +1 -1
- data/lib/pulsar/consumer_configuration.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdac30fc88a91584ef35377492dbbb8dbde43cb1
|
4
|
+
data.tar.gz: f258ede389a3034b8f783f586489db1e15e8d781
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dedd175bbbbe43ec40925cbbd55e738157272a89a4a0b27635b51adad5fef51e5faf284c0e683365c9d83a6b4904407673ccfe1670424a89b924fe74d97ff5c
|
7
|
+
data.tar.gz: 30cb9298ceca90c1178759d9b08f64951947e0c4c9464af6f1386dccb1402ca77aae900ba01a00e6f615b1bda8a2b20bdb6f8bb09f88a7e36e837600599a27bb
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ the `.pre` suffix in the Gemfile to install it via Bundler.
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
|
30
|
+
Setup and basic `consumer.receive` example:
|
31
31
|
|
32
32
|
```ruby
|
33
33
|
# have these in your shell with appropriate values
|
@@ -48,10 +48,35 @@ producer.send("Hello, world!")
|
|
48
48
|
# named "hello-consumer"
|
49
49
|
subscription = "hello-consumer"
|
50
50
|
consumer = client.subscribe(topic, subscription)
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
|
52
|
+
msg = consumer.receive
|
53
|
+
message = msg.data
|
54
|
+
puts "got #{message}"
|
55
|
+
consumer.acknolwedge(msg)
|
56
|
+
```
|
57
|
+
|
58
|
+
Convenience method for listening to messages in a loop:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
consumer.listen do |message, _, done|
|
62
|
+
# process message here; call done to stop the loop.
|
63
|
+
# messages are auto-acknowledged.
|
64
|
+
puts "got #{message}"
|
65
|
+
done.call()
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
Convenience method for listening on a separate thread:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
listenerThread = consumer.listen_in_thread do |message, _, done|
|
73
|
+
# process message here; call done to stop the loop.
|
74
|
+
# messages are auto-acknowledged.
|
75
|
+
puts "got #{message}"
|
76
|
+
done.call()
|
54
77
|
end
|
78
|
+
# ...
|
79
|
+
listenerThread.join # wait for the thread to finish
|
55
80
|
```
|
56
81
|
|
57
82
|
(more documentation coming; see TODO.md)
|
data/ext/bindings/bindings.cpp
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
#include "producer.hpp"
|
5
5
|
#include "consumer.hpp"
|
6
6
|
#include "client.hpp"
|
7
|
+
#include "util.hpp"
|
7
8
|
|
8
9
|
using namespace Rice;
|
9
10
|
|
@@ -11,6 +12,7 @@ extern "C"
|
|
11
12
|
void Init_bindings()
|
12
13
|
{
|
13
14
|
Module rb_mPulsar = define_module("Pulsar");
|
15
|
+
bind_errors(rb_mPulsar);
|
14
16
|
bind_message(rb_mPulsar);
|
15
17
|
bind_producer(rb_mPulsar);
|
16
18
|
bind_consumer(rb_mPulsar);
|
data/ext/bindings/consumer.cpp
CHANGED
@@ -11,25 +11,30 @@ namespace pulsar_rb {
|
|
11
11
|
|
12
12
|
typedef struct {
|
13
13
|
pulsar::Consumer& consumer;
|
14
|
+
unsigned int timeout_ms;
|
14
15
|
pulsar::Message message;
|
15
16
|
pulsar::Result result;
|
16
17
|
} consumer_receive_job;
|
17
18
|
|
18
19
|
void* consumer_receive_nogvl(void* jobPtr) {
|
19
20
|
consumer_receive_job& job = *(consumer_receive_job*)jobPtr;
|
20
|
-
job.
|
21
|
+
if (job.timeout_ms > 0) {
|
22
|
+
job.result = job.consumer.receive(job.message, job.timeout_ms);
|
23
|
+
} else {
|
24
|
+
job.result = job.consumer.receive(job.message);
|
25
|
+
}
|
21
26
|
return nullptr;
|
22
27
|
}
|
23
28
|
|
24
|
-
pulsar::Message consumer_receive(pulsar::Consumer& consumer) {
|
25
|
-
consumer_receive_job job = { consumer };
|
29
|
+
pulsar::Message consumer_receive(pulsar::Consumer& consumer, unsigned int timeout_ms) {
|
30
|
+
consumer_receive_job job = { consumer, timeout_ms };
|
26
31
|
rb_thread_call_without_gvl(&consumer_receive_nogvl, &job, RUBY_UBF_IO, nullptr);
|
27
32
|
CheckResult(job.result);
|
28
33
|
return job.message;
|
29
34
|
}
|
30
35
|
|
31
|
-
Message::ptr Consumer::receive() {
|
32
|
-
pulsar::Message message = consumer_receive(_consumer);
|
36
|
+
Message::ptr Consumer::receive(unsigned int timeout_ms) {
|
37
|
+
pulsar::Message message = consumer_receive(_consumer, timeout_ms);
|
33
38
|
return Message::ptr(new Message(message));
|
34
39
|
}
|
35
40
|
|
@@ -48,7 +53,7 @@ using namespace Rice;
|
|
48
53
|
void bind_consumer(Module &module) {
|
49
54
|
define_class_under<pulsar_rb::Consumer>(module, "Consumer")
|
50
55
|
.define_constructor(Constructor<pulsar_rb::Consumer>())
|
51
|
-
.define_method("receive", &pulsar_rb::Consumer::receive)
|
56
|
+
.define_method("receive", &pulsar_rb::Consumer::receive, (Arg("timeout_ms") = 0))
|
52
57
|
.define_method("acknowledge", &pulsar_rb::Consumer::acknowledge)
|
53
58
|
.define_method("negative_acknowledge", &pulsar_rb::Consumer::negative_acknowledge)
|
54
59
|
;
|
data/ext/bindings/consumer.hpp
CHANGED
@@ -14,7 +14,7 @@ namespace pulsar_rb {
|
|
14
14
|
Consumer() {};
|
15
15
|
Consumer(const pulsar::Consumer& consumer) : _consumer(consumer) {}
|
16
16
|
|
17
|
-
Message::ptr receive();
|
17
|
+
Message::ptr receive(unsigned int timeout_ms=0);
|
18
18
|
void acknowledge(const Message& message);
|
19
19
|
void negative_acknowledge(const Message& message);
|
20
20
|
|
data/ext/bindings/util.cpp
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
#include <pulsar/Client.h>
|
2
2
|
|
3
3
|
#include "util.hpp"
|
4
|
+
#include "rice/Exception.hpp"
|
4
5
|
|
5
|
-
using namespace
|
6
|
+
using namespace Rice;
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
VALUE rb_ePulsarError = Qnil;
|
9
|
+
VALUE rb_ePulsarError_Timeout = Qnil;
|
10
|
+
|
11
|
+
void bind_errors(Module &module) {
|
12
|
+
rb_ePulsarError = rb_define_class_under(module.value(), "Error", rb_eStandardError);
|
13
|
+
rb_ePulsarError_Timeout = rb_define_class_under(rb_ePulsarError, "Timeout", rb_ePulsarError);
|
14
|
+
}
|
15
|
+
|
16
|
+
void CheckResult(pulsar::Result res) {
|
17
|
+
if (res == pulsar::ResultTimeout) {
|
18
|
+
throw Exception(rb_ePulsarError_Timeout, "pulsar timeout");
|
19
|
+
}
|
20
|
+
else if (res != ResultOk) {
|
21
|
+
throw Exception(rb_ePulsarError, "unexpected pulsar exception: %d", res);
|
10
22
|
}
|
11
23
|
}
|
data/ext/bindings/util.hpp
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
#ifndef __PULSAR_RUBY_CLIENT_UTIL_HPP
|
2
2
|
#define __PULSAR_RUBY_CLIENT_UTIL_HPP
|
3
3
|
|
4
|
+
#include "rice/Module.hpp"
|
4
5
|
#include <pulsar/Client.h>
|
5
6
|
|
6
7
|
using namespace pulsar;
|
7
8
|
|
8
|
-
struct PulsarException {
|
9
|
-
Result _result;
|
10
|
-
PulsarException(Result res) :
|
11
|
-
_result(res) {}
|
12
|
-
};
|
13
|
-
|
14
9
|
void CheckResult(Result res);
|
15
10
|
|
11
|
+
void bind_errors(Rice::Module& module);
|
12
|
+
|
16
13
|
#endif
|
data/lib/pulsar/client.rb
CHANGED
@@ -37,8 +37,10 @@ module Pulsar
|
|
37
37
|
super(topic, config)
|
38
38
|
end
|
39
39
|
|
40
|
-
def subscribe(topic, subscription_name, config=
|
41
|
-
config
|
40
|
+
def subscribe(topic, subscription_name, config={})
|
41
|
+
unless config.is_a?(Pulsar::ConsumerConfiguration)
|
42
|
+
config = Pulsar::ConsumerConfiguration.new(config)
|
43
|
+
end
|
42
44
|
super(topic, subscription_name, config)
|
43
45
|
end
|
44
46
|
end
|
data/lib/pulsar/consumer.rb
CHANGED