Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
  1. Download Protobuf for the target language of choice, build it, and install it.
  2. Download the latest pre-built release of Geode and install it.
  3. Start a Geode locator, start a Geode server, and create a region with the following gfsh commands:

    Code Block
    languagebash
    themeEmacs
    titleStart Server
    gfsh>start locator --name=locator --bind-address=localhost --port=10334
    ...
    gfsh>start server --name=server --bind-address=localhost --server-port=40404 --J=-Dgeode.feature-protobuf-protocol=true
    ...
    gfsh>create region --name=SampleData --type=REPLICATE
    Member | Status
    ------ | ----------------------------------------
    server | Region "/SampleData" created on "server"
  4. Extract the Protobuf message definition artifacts from the Geode release: $GEODE_HOME/tools/ClientProtocol/geode-protobuf-definitions-<version-number>.zip.
  5. Generate the language bindings from the message definitions using the relevant target language Protobuf library using the appropriate Protobuf utility such as protoc. Example:

    Code Block
    $PROTOBUF/bin/protoc -I=$PROTOBUF/include/ -I=`pwd` --java_out=`pwd` v1/*.proto
  6. Create your application that connects a TCP socket to the server running on the host localhost on port 40404.
  7. Set up communication with the server. Within your application, write byte 0x6E (decimal 110) to the socket to select Protobuf communication. Then write byte 0x01 (decimal 1) to the socket to indicate the major version number of the Protobuf message definitions that are to be used.
    1. In order to communicate with a locator, the handshake must begin with four 0x00 bytes. The whole sequence would thus be 0x00,0x00,0x00,0x00,0x6E,0x01 ].

  8. Within your application, build a handshake request message, write it in a delimited fashion to the socket, and read the handshake response message in a delimited fashion from it. Note that you are always reading and writing a message which contains a handshake request.

    Code Block
    languagejs
    themeEmacs
    titlehandshakeRequest
    message {
       request {
            handshakeRequest {
                majorVersion: 1
    	        minorVersion: 1
    	    }
        }
    }

    Your implementation language may not provide an API to explicitly read and/or write delimited messages. These messages are prepended with the message length encoded as a varint value. If you do not have an appropriate API, you may need to read and decode this value first, in order to determine how much data to read from the network to receive a complete message.
    Also be aware that messages may not arrive in one packet and may require multiple read() calls to receive all data from the network.

    Code Block
    languagejs
    themeEmacs
    titlehandshakeResponse
    message {
        response {
            handshakeResponse {
                serverMajorVersion: 1
                serverMinorVersion: 1
                handshakePassed: true
            }
        }
    }
  9. To exercise the protocol to interact with the server, within your application build a put request message to put the value bar for the key foo, write it in a delimited fashion to the socket, and read the put response message in a delimited fashion from it.

    Code Block
    languagejs
    themeEmacs
    titleputRequest
    message {
        request {
             putRequest {
                 regionName: "SampleData"
                 entry {
                 key {
                     stringResult: "foo"
                 }
                 value {
                     stringResult: "bar"
                 }
            }
        }
    }
    Code Block
    languagejs
    themeEmacs
    titleputResponse
    message {
        response {
            putResponse {}
        }
    }


    If an error occurs, your message will contain an ErrorResponse:

    Code Block
    languagejs
    themeEmacs
    titleerrorResponse
    message {
        response {
            errorResponse {
                errorCode: 2100
                message: "Region passed by client did not exist: FOO"
            }
        }
    }



  10. Outside your application, verify that the put request message took effect with the following gfsh command:

    Code Block
    languagebash
    themeEmacs
    titleVerify Put
    gfsh>get --region=SampleData --key=foo
    Result      : true
    Key Class   : java.lang.String
    Key         : foo
    Value Class : java.lang.String
    Value       : bar

...