torquebox-message-encodings 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .idea
4
+ .rvmrc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
@@ -0,0 +1,3 @@
1
+ script: bundle exec rspec
2
+ rvm:
3
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in torquebox-message-encodings.gemspec
4
+ gemspec :path => './'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kevin Olbrich
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Torquebox::Message::Formats
2
+
3
+ [![Build Status](https://travis-ci.org/olbrich/torquebox-message-encodings.png?branch=master)](https://travis-ci.org/olbrich/torquebox-message-encodings)
4
+
5
+ Provides some extra serialization formats for torquebox messages including:
6
+
7
+ * Msgpack (http://msgpack.org/)
8
+ * BSON (http://bsonspec.org/)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'torquebox-message-formats', :require => 'bson'
15
+ gem 'torquebox-message-formats', :require => 'msgpack'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install torquebox-message-formats
24
+
25
+ ## Usage
26
+
27
+ see http://torquebox.org/documentation/LATEST/messaging.html#message-encodings
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ require "torquebox-message-encodings/version"
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'bson'
3
+ rescue LoadError => ex
4
+ raise RuntimeError.new( "Unable to load the bson gem. Verify that is installed and in your Gemfile (if using Bundler)" )
5
+ end
6
+
7
+ module TorqueBox
8
+ module Messaging
9
+ class BSONMessage < Message
10
+ ENCODING = :bson
11
+ JMS_TYPE = :bytes
12
+
13
+ def encode(message)
14
+ unless message.nil?
15
+ bsoned = ::BSON.serialize(message, false)
16
+ @jms_message.write_bytes( bsoned.to_s.to_java_bytes )
17
+ end
18
+ end
19
+
20
+ def decode
21
+ if (length = @jms_message.get_body_length) > 0
22
+ bytes = Java::byte[length].new
23
+ @jms_message.read_bytes( bytes )
24
+ @jms_message.reset
25
+ ::BSON.deserialize( String.from_java_bytes( bytes ) )
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ Message.register_encoding( BSONMessage )
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'msgpack'
3
+ rescue LoadError => ex
4
+ raise RuntimeError.new( "Unable to load the msgpack-jruby gem. Verify that is installed and in your Gemfile (if using Bundler)" )
5
+ end
6
+
7
+ module TorqueBox
8
+ module Messaging
9
+ class MsgpackMessage < Message
10
+ ENCODING = :msgpack
11
+ JMS_TYPE = :bytes
12
+
13
+ def encode(message)
14
+ unless message.nil?
15
+ msgpacked = ::MessagePack.pack(message)
16
+ @jms_message.write_bytes( msgpacked.to_s.to_java_bytes )
17
+ end
18
+ end
19
+
20
+ def decode
21
+ if (length = @jms_message.get_body_length) > 0
22
+ bytes = Java::byte[length].new
23
+ @jms_message.read_bytes( bytes )
24
+ @jms_message.reset
25
+ ::MessagePack.unpack( String.from_java_bytes( bytes ) )
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ Message.register_encoding( MsgpackMessage )
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ module Torquebox
2
+ module Message
3
+ module Encodings
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,48 @@
1
+ require 'java'
2
+ require 'jboss-jms-api_1.1_spec-1.0.1.Final.jar'
3
+ require 'torquebox/messaging/message'
4
+ require 'lib/torquebox-message-encodings/bson'
5
+
6
+ include TorqueBox::Messaging
7
+ class MockBSONMessage
8
+ include javax.jms::BytesMessage
9
+ attr_accessor :bytes
10
+
11
+ def get_string_property(_)
12
+ "bson"
13
+ end
14
+
15
+ def write_bytes(packed_message)
16
+ self.bytes = packed_message
17
+ end
18
+
19
+ def get_body_length
20
+ self.bytes.size
21
+ end
22
+
23
+ def read_bytes(buffer)
24
+ self.bytes.each_with_index do |byte, index|
25
+ buffer.ubyte_set(index, byte)
26
+ end
27
+ get_body_length
28
+ end
29
+
30
+ def reset; end
31
+ end
32
+
33
+ describe TorqueBox::Messaging::BSONMessage do
34
+
35
+ before(:each) do
36
+ @message = Message.new( MockBSONMessage.new )
37
+ end
38
+
39
+ it "should BSON encode a message" do
40
+ String.from_java_bytes(@message.encode(key: 'bson')).should == "\x13\x00\x00\x00\x02key\x00\x05\x00\x00\x00bson\x00\x00"
41
+ end
42
+
43
+ it "should decode a BSON message" do
44
+ @message.encode(key: 'bson')
45
+ @message.decode.should == {"key"=>"bson"}
46
+ end
47
+
48
+ end
@@ -0,0 +1,48 @@
1
+ require 'java'
2
+ require 'jboss-jms-api_1.1_spec-1.0.1.Final.jar'
3
+ require 'torquebox/messaging/message'
4
+ require 'lib/torquebox-message-encodings/msgpack'
5
+
6
+ include TorqueBox::Messaging
7
+ class MockMsgpackMessage
8
+ include javax.jms::BytesMessage
9
+ attr_accessor :bytes
10
+
11
+ def get_string_property(_)
12
+ "msgpack"
13
+ end
14
+
15
+ def write_bytes(packed_message)
16
+ self.bytes = packed_message.clone
17
+ end
18
+
19
+ def get_body_length
20
+ self.bytes.size
21
+ end
22
+
23
+ def read_bytes(buffer)
24
+ self.bytes.each_with_index do |byte, index|
25
+ buffer.ubyte_set(index, byte)
26
+ end
27
+ get_body_length
28
+ end
29
+
30
+ def reset; end
31
+ end
32
+
33
+ describe TorqueBox::Messaging::MsgpackMessage do
34
+
35
+ before(:each) do
36
+ @message = Message.new( MockMsgpackMessage.new )
37
+ end
38
+
39
+ it "should MSGPACK encode a message" do
40
+ String.from_java_bytes(@message.encode(key: 'msgpack')).should == "\x81\xA3key\xA7msgpack"
41
+ end
42
+
43
+ it "should decode a MSGPACK message" do
44
+ @message.encode(key: 'msgpack')
45
+ @message.decode.should == {"key"=>"msgpack"}
46
+ end
47
+
48
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'torquebox-message-encodings/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "torquebox-message-encodings"
8
+ gem.version = Torquebox::Message::Encodings::VERSION
9
+ gem.authors = ["Kevin Olbrich"]
10
+ gem.email = ["kevin.olbrich@gmail.com"]
11
+ gem.description = %q{Provides additional message serialization formats for torquebox}
12
+ gem.summary = %q{Provides additional message serialization formats for torquebox}
13
+ gem.homepage = "https://github.com/olbrich/torquebox-message-encodings"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_runtime_dependency "torquebox-messaging", "~> 2.0"
20
+ gem.add_development_dependency "rspec"
21
+ gem.add_development_dependency "bson"
22
+ gem.add_development_dependency "msgpack-jruby"
23
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: torquebox-message-encodings
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Kevin Olbrich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: torquebox-messaging
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '2.0'
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: !binary |-
37
+ MA==
38
+ none: false
39
+ requirement: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: !binary |-
44
+ MA==
45
+ none: false
46
+ prerelease: false
47
+ type: :development
48
+ - !ruby/object:Gem::Dependency
49
+ name: bson
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: !binary |-
55
+ MA==
56
+ none: false
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: !binary |-
62
+ MA==
63
+ none: false
64
+ prerelease: false
65
+ type: :development
66
+ - !ruby/object:Gem::Dependency
67
+ name: msgpack-jruby
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: !binary |-
73
+ MA==
74
+ none: false
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: !binary |-
80
+ MA==
81
+ none: false
82
+ prerelease: false
83
+ type: :development
84
+ description: Provides additional message serialization formats for torquebox
85
+ email:
86
+ - kevin.olbrich@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/torquebox-message-encodings.rb
98
+ - lib/torquebox-message-encodings/bson.rb
99
+ - lib/torquebox-message-encodings/msgpack.rb
100
+ - lib/torquebox-message-encodings/version.rb
101
+ - spec/bson_spec.rb
102
+ - spec/msgpack_spec.rb
103
+ - torquebox-message-encodings.gemspec
104
+ homepage: https://github.com/olbrich/torquebox-message-encodings
105
+ licenses: []
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: !binary |-
115
+ MA==
116
+ none: false
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: !binary |-
122
+ MA==
123
+ none: false
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 1.8.24
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Provides additional message serialization formats for torquebox
130
+ test_files:
131
+ - spec/bson_spec.rb
132
+ - spec/msgpack_spec.rb