Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > RightScale Grid Technical User Guide > Creating Your Own Message Encoder

Creating Your Own Message Encoder

While you are free to use any internal data format for work units, the job producer, RightScale Grid worker daemon, and job consumer must all read and write work units with the same set of encoding and decoding functions.

In most cases it's sufficient to use RightScale Grid's default internal codec, which encodes Ruby objects into YAML and later decodes the YAML back into Ruby objects. If your situation is unusual enough to require a custom message encoding, you must implement a custom codec class and configure RightScale Grid to use it. Any such ‘codec’ class can be used provided that the name is given in the message_decoder field of rightworker.yml file (generated by the ServerTemplate).

Here is a very simple example of a codec class:

class RightYamlCodec
	# Unpacks a message using YAML
	def unpack(packed_message)
		YAML.load(packed_message)
	end
	# Packs a message using YAML
	def pack(unpacked_results)
		YAML.dump(unpacked_results)
	end
end

This sample codec is included with RightScale Grid as the file 'right_yaml_codec.rb'. Any user-created codec file must be located in the same directory as the rightworker.yml in order for the RightScale Grid worker daemon to find it.of

Sample of a packed message:
---
created_at: 2007-04-23 09:10:52 UTC
worker_name: RightPhotoWorker
s3_download:
- bucket/key1
- bucket/key2
any_other_var_name_1: value_1
...
any_other_var_name_N: value_N 
---

Sample of an unpacked message:
{
‘created_at’ => ‘2007-04-23 09:10:52 UTC’
'worker_name' => 'RightPhotoWorker',
's3_download' => ['bucket/key2',
'bucket/key2']
‘any_other_var_name_1’ => value_1
...
any_other_var_name_N: value_N
}
---

 

 

You must to post a comment.
Last modified
23:19, 16 May 2013

Tags

This page has no custom tags.

Classifications

This page has no classifications.

Announcements

None


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.