magellan-publisher 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d38adff420cc28de137ce67afb59bd8109e0a3d9
4
- data.tar.gz: edf2f4bd089b5c5ca8507ffaa022130a37685782
3
+ metadata.gz: 8009042b4cf90b3a91fd1063b3fd7f558eba3b87
4
+ data.tar.gz: 40ba2d7b358fb62dc7fe365698214469cbd609ab
5
5
  SHA512:
6
- metadata.gz: eecfefcf1d081102103ff4d317ae41f71c6b7c7bb2d969494de5b7ef78b7a17481d5da196e5786f11de4bf9b9333076d19cd744e92839bda198cfeb32b02ce2f
7
- data.tar.gz: c12bceffff43b22e316c5398e70548ef0a0dedd8bfe1e8e67cd3cde468fc37fe571be19e637b6c14bbf8addc4f65a42862d67257f183239c4b3f23faf5d3d9db
6
+ metadata.gz: c250a3822a1beb4232a224d5b8a0e8ec1ca9ecef23e56567515cd4b6abd4aa1285867ecfba9cafa6468bf75dbdb5166c1be92d294e0d2ba8b090d61ab765356f
7
+ data.tar.gz: 3208a67faed86c583004da0caf663790e6b1c6e5ca171770887d52cf04841874c9d10d7c62c5c9c62587bde34f04ecfaf598310d9668372fb09e38b7e275db75
@@ -1,5 +1,5 @@
1
1
  module Magellan
2
2
  class Publisher
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -2,8 +2,10 @@
2
2
 
3
3
  module Magellan
4
4
  class Publisher
5
+ class MessageTooLong < StandardError; end
6
+
5
7
  def initialize(host: nil, port: nil, vhost: nil, user: nil, pass: nil, timeout: nil)
6
- # RabbitMQへの接続設定を作成
8
+ # connection settings for AMQP
7
9
  connection_settings = {
8
10
  host: load_env_as_default(host, ['MAGELLAN_PUBLISH_AMQP_ADDR'], :string),
9
11
  port: load_env_as_default(port, ['MAGELLAN_PUBLISH_AMQP_PORT'], :integer),
@@ -19,10 +21,14 @@ module Magellan
19
21
 
20
22
  exchange_name = ENV["MAGELLAN_PUBLISH_EXCHANGE"] || "magellan_publish"
21
23
 
22
- # no_declareを設定しない場合、Exchangeに対してdeclareを実行してしまい、
23
- # Acess Contorolにひっかかりエラーとなります
24
- # exchangeはmagellan-conductorによって作成済みの想定です
24
+ # here :no_declare options should be true to get rid of Access Control Error.
25
25
  @exchange = @channel.exchange(exchange_name, no_declare: true)
26
+
27
+ # publish message size limit
28
+ @message_size_limit = load_env_as_default(nil, ["MAGELLAN_PUBLISH_MESSAGE_SIZE_LIMIT"], :integer) || (256 * 1024 * 1024)
29
+ # message size limit should be treated equally with MQTT message.
30
+ # substruct MQTT's topic length + packet identifier size (4 bytes)
31
+ @message_size_limit -= 4
26
32
  end
27
33
 
28
34
  def convert_topic(mqtt_topic)
@@ -31,6 +37,9 @@ module Magellan
31
37
  private :convert_topic
32
38
 
33
39
  def publish(topic, body)
40
+ if topic.bytesize + body.bytesize > @message_size_limit
41
+ raise MessageTooLong, "publishing topic(#{topic.bytesize} bytes) and payload(#{body.bytesize}) exceed message size limitation#{@message_size_limit}."
42
+ end
34
43
  @exchange.publish(body, routing_key: convert_topic(topic))
35
44
  end
36
45
 
@@ -16,22 +16,45 @@ describe Magellan::Publisher do
16
16
  @bunny = BunnyMock.new
17
17
  channel = @bunny.create_channel
18
18
  @exchange = @bunny.exchange('test_exchange', type: :direct, durable: false, auto_delete: false)
19
- expect(@exchange).to receive(:publish).with(@payload, routing_key: @rabbitmq_topic)
20
19
 
21
20
  allow(Bunny ).to receive(:new).and_return(@bunny)
22
21
  allow(@bunny ).to receive(:create_channel).and_return(channel)
23
22
  allow(channel).to receive(:exchange).with('test_exchange', no_declare: true).and_return(@exchange)
24
23
 
25
24
  ENV["MAGELLAN_PUBLISH_EXCHANGE"] = "test_exchange"
26
- @publisher = Magellan::Publisher.new(host: "127.0.0.1",
27
- port: 5672,
28
- vhost: "/customer1.sample_project",
29
- user: "customer1.sample_project",
30
- pass: "pasw1")
31
25
  end
32
26
 
33
- it do
34
- @publisher.publish(@topic, @payload)
27
+ context "normally" do
28
+ before do
29
+ expect(@exchange).to receive(:publish).with(@payload, routing_key: @rabbitmq_topic)
30
+ @publisher = Magellan::Publisher.new(host: "127.0.0.1",
31
+ port: 5672,
32
+ vhost: "/customer1.sample_project",
33
+ user: "customer1.sample_project",
34
+ pass: "pasw1")
35
+ end
36
+
37
+ it do
38
+ @publisher.publish(@topic, @payload)
39
+ end
40
+ end
41
+
42
+ context "message size limit exceed" do
43
+ before do
44
+ ENV["MAGELLAN_PUBLISH_MESSAGE_SIZE_LIMIT"] = (@topic.size + @payload.size + 1).to_s
45
+ @publisher = Magellan::Publisher.new(host: "127.0.0.1",
46
+ port: 5672,
47
+ vhost: "/customer1.sample_project",
48
+ user: "customer1.sample_project",
49
+ pass: "pasw1")
50
+ end
51
+ after do
52
+ ENV["MAGELLAN_PUBLISH_MESSAGE_SIZE_LIMIT"] = nil
53
+ end
54
+
55
+ it do
56
+ expect { @publisher.publish(@topic, @payload) }.to raise_error(Magellan::Publisher::MessageTooLong)
57
+ end
35
58
  end
36
59
  end
37
60
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomoyuki Chikanaga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-11 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.2.2
120
+ rubygems_version: 2.4.6
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: ''