| 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 6 | <title>Using Replication Manager message channels</title> |
| 7 | <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> |
| 8 | <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> |
| 9 | <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" /> |
| 10 | <link rel="up" href="rep.html" title="Chapter 12. Berkeley DB Replication" /> |
| 11 | <link rel="prev" href="rep_clock_skew.html" title="Clock Skew" /> |
| 12 | <link rel="next" href="rep_twosite.html" title="Special considerations for two-site replication groups" /> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">Using Replication Manager message channels</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="rep_clock_skew.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 12. |
| 26 | Berkeley DB Replication |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="rep_twosite.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="repmgr_channels"></a>Using Replication Manager message channels</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <div class="toc"> |
| 42 | <dl> |
| 43 | <dt> |
| 44 | <span class="sect2"> |
| 45 | <a href="repmgr_channels.html#dbchannel_class">DB_CHANNEL</a> |
| 46 | </span> |
| 47 | </dt> |
| 48 | <dt> |
| 49 | <span class="sect2"> |
| 50 | <a href="repmgr_channels.html#dbchannel_send">Sending messages over a message channel</a> |
| 51 | </span> |
| 52 | </dt> |
| 53 | <dt> |
| 54 | <span class="sect2"> |
| 55 | <a href="repmgr_channels.html#dbchannel_receive">Receiving messages</a> |
| 56 | </span> |
| 57 | </dt> |
| 58 | </dl> |
| 59 | </div> |
| 60 | <p> |
| 61 | The various sites comprising a replication group frequently need to |
| 62 | communicate with one another. Mostly, these messages are handled |
| 63 | for you internally by the Replication Manager. However, your |
| 64 | application may have a requirement to pass messages beyond what the |
| 65 | Replication Manager requires in order to satisfy its own internal |
| 66 | workings. |
| 67 | </p> |
| 68 | <p> |
| 69 | For this reason, you can access and use the Replication Manager's |
| 70 | internal message channels. You do this by using the |
| 71 | <code class="literal">DB_CHANNEL</code> class, and by implementing a message |
| 72 | handling function on each of your sites. |
| 73 | </p> |
| 74 | <p> |
| 75 | Note that an example of using Replication Manager message channels |
| 76 | is available in the distribution. See |
| 77 | <a class="xref" href="rep_ex_chan.html" title="Ex_rep_chan: a Replication Manager channel example">Ex_rep_chan: a Replication Manager |
| 78 | channel example</a> |
| 79 | for more information. |
| 80 | </p> |
| 81 | <div class="sect2" lang="en" xml:lang="en"> |
| 82 | <div class="titlepage"> |
| 83 | <div> |
| 84 | <div> |
| 85 | <h3 class="title"><a id="dbchannel_class"></a>DB_CHANNEL</h3> |
| 86 | </div> |
| 87 | </div> |
| 88 | </div> |
| 89 | <p> |
| 90 | The <code class="literal">DB_CHANNEL</code> class provides a series of |
| 91 | methods which allow you to send messages to the other sites in |
| 92 | your replication group. You create a <code class="literal">DB_CHANNEL</code> |
| 93 | handle using the <a href="../api_reference/C/repmgr_channel.html" class="olink">DB_ENV->repmgr_channel()</a> method. When you are |
| 94 | done with the handle, close it using the <a href="../api_reference/C/dbchannel_close.html" class="olink">DB_CHANNEL->close()</a> |
| 95 | method. A closed handle must never be accessed again. Note that |
| 96 | all channel handles should be closed before the associated |
| 97 | environment handle is closed. Also, allow all message |
| 98 | operations to complete on the channel before closing the |
| 99 | handle. |
| 100 | </p> |
| 101 | <p> |
| 102 | When you create a <code class="literal">DB_CHANNEL</code> handle, you |
| 103 | indicate what channel you want to use. Possibilities are: |
| 104 | </p> |
| 105 | <div class="itemizedlist"> |
| 106 | <ul type="disc"> |
| 107 | <li> |
| 108 | <p> |
| 109 | The numerical env ID of a remote site in the |
| 110 | replication group. |
| 111 | </p> |
| 112 | </li> |
| 113 | <li> |
| 114 | <p> |
| 115 | <code class="literal">DB_EID_MASTER</code> |
| 116 | </p> |
| 117 | <p> |
| 118 | Messages sent on this channel are sent only to the |
| 119 | master site. Note that messages are always sent to |
| 120 | the current master, even if the master has changed |
| 121 | since the channel was opened. |
| 122 | </p> |
| 123 | <p> |
| 124 | If the local site is the master, then sending messages |
| 125 | on this channel will result in the local site |
| 126 | receiving those messages echoed back to itself. |
| 127 | </p> |
| 128 | </li> |
| 129 | </ul> |
| 130 | </div> |
| 131 | </div> |
| 132 | <div class="sect2" lang="en" xml:lang="en"> |
| 133 | <div class="titlepage"> |
| 134 | <div> |
| 135 | <div> |
| 136 | <h3 class="title"><a id="dbchannel_send"></a>Sending messages over a message channel</h3> |
| 137 | </div> |
| 138 | </div> |
| 139 | </div> |
| 140 | <p> |
| 141 | You can send any message you want over a message channel. The |
| 142 | message can be as simple as a character string and as complex |
| 143 | as a large data structure. However, before you can send the |
| 144 | message, you must encapsulate it within one or more <a href="../api_reference/C/dbt.html" class="olink">DBT</a>s. |
| 145 | This means <a class="link" href="am_misc_struct.html" title="Storing C/C++ structures/objects">marshaling the message</a> |
| 146 | if it is contained within a complex data structure. |
| 147 | </p> |
| 148 | <p> |
| 149 | The methods that you use to send messages all accept an array of |
| 150 | <a href="../api_reference/C/dbt.html" class="olink">DBT</a>s. This means that in most circumstances it is perfectly |
| 151 | acceptable to send multi-part messages. |
| 152 | </p> |
| 153 | <p> |
| 154 | Messages may be sent either asynchronously or synchronously. |
| 155 | To send a message asynchronously, use the <a href="../api_reference/C/dbchannel_send_msg.html" class="olink">DB_CHANNEL->send_msg()</a> |
| 156 | method. This method sends its message and then immediately |
| 157 | returns without waiting for any sort of a response. |
| 158 | |
| 159 | |
| 160 | </p> |
| 161 | <p> |
| 162 | To send a message synchronously, use the |
| 163 | <a href="../api_reference/C/dbchannel_send_request.html" class="olink">DB_CHANNEL->send_request()</a> method. This method blocks until it |
| 164 | receives a response from the site to which it sent the message |
| 165 | (or until a timeout threshold is reached). |
| 166 | |
| 167 | |
| 168 | </p> |
| 169 | <div class="sect3" lang="en" xml:lang="en"> |
| 170 | <div class="titlepage"> |
| 171 | <div> |
| 172 | <div> |
| 173 | <h4 class="title"><a id="dbchannel_respond"></a>Message Responses</h4> |
| 174 | </div> |
| 175 | </div> |
| 176 | </div> |
| 177 | <p> |
| 178 | Message responses are required if a message is sent on a |
| 179 | channel using the <a href="../api_reference/C/dbchannel_send_request.html" class="olink">DB_CHANNEL->send_request()</a> method. That |
| 180 | method accepts the address of a single <a href="../api_reference/C/dbt.html" class="olink">DBT</a> which is used |
| 181 | to receive the response from the remote site. |
| 182 | </p> |
| 183 | <p> |
| 184 | Message responses are encapsulated in a single <a href="../api_reference/C/dbt.html" class="olink">DBT</a>. The |
| 185 | response can be anything from a complex data structure, to |
| 186 | a string, to a simple type, to no information at all. In |
| 187 | the latter case, receipt of the <a href="../api_reference/C/dbt.html" class="olink">DBT</a> is sufficient to |
| 188 | indicate that the request was received at the remote site. |
| 189 | </p> |
| 190 | <p> |
| 191 | Responses are sent back from the remote system using its |
| 192 | message handling function. Usually that function calls |
| 193 | <a href="../api_reference/C/dbchannel_send_msg.html" class="olink">DB_CHANNEL->send_msg()</a> to send a single response. |
| 194 | </p> |
| 195 | <p> |
| 196 | The response must be contained in a single <a href="../api_reference/C/dbt.html" class="olink">DBT</a>. If a |
| 197 | multi-part response is required by the application, you can |
| 198 | configure the response <a href="../api_reference/C/dbt.html" class="olink">DBT</a> that you provide to |
| 199 | <a href="../api_reference/C/dbchannel_send_request.html" class="olink">DB_CHANNEL->send_request()</a> for |
| 200 | <a class="link" href="am_misc_bulk.html" title="Retrieving and updating records in bulk">bulk operations</a>. |
| 201 | </p> |
| 202 | </div> |
| 203 | </div> |
| 204 | <div class="sect2" lang="en" xml:lang="en"> |
| 205 | <div class="titlepage"> |
| 206 | <div> |
| 207 | <div> |
| 208 | <h3 class="title"><a id="dbchannel_receive"></a>Receiving messages</h3> |
| 209 | </div> |
| 210 | </div> |
| 211 | </div> |
| 212 | <p> |
| 213 | Messages received at a remote site are handled using a callback |
| 214 | function. This function is configured for the local environment |
| 215 | using the <a href="../api_reference/C/repmgr_msg_dispatch.html" class="olink">DB_ENV->repmgr_msg_dispatch()</a> method. For best results, |
| 216 | the message dispatch function should be configured for the |
| 217 | local environment before replication is started. In this way, |
| 218 | you do not run the risk of missing messages sent after |
| 219 | replication has started but before the message dispatch |
| 220 | function is configured for the environment. |
| 221 | </p> |
| 222 | <p> |
| 223 | The callback configured by <a href="../api_reference/C/repmgr_msg_dispatch.html" class="olink">DB_ENV->repmgr_msg_dispatch()</a> accepts |
| 224 | four parameters of note: |
| 225 | </p> |
| 226 | <div class="itemizedlist"> |
| 227 | <ul type="disc"> |
| 228 | <li> |
| 229 | <p> |
| 230 | A response channel. This is the channel the function |
| 231 | will use to response to the message, if a response is |
| 232 | required. To respond to the message, the function uses |
| 233 | the <a href="../api_reference/C/dbchannel_send_msg.html" class="olink">DB_CHANNEL->send_msg()</a> method. |
| 234 | </p> |
| 235 | </li> |
| 236 | <li> |
| 237 | <p> |
| 238 | An array of <a href="../api_reference/C/dbt.html" class="olink">DBT</a>s. These hold the message that this |
| 239 | function must handle. |
| 240 | </p> |
| 241 | </li> |
| 242 | <li> |
| 243 | <p> |
| 244 | A numerical value that indicates how many elements the |
| 245 | previously described array holds. |
| 246 | </p> |
| 247 | </li> |
| 248 | <li> |
| 249 | <p> |
| 250 | A flag that indicates whether the message requires a |
| 251 | response. If the flag is set to |
| 252 | <code class="literal">DB_REPMGR_NEED_RESPONSE</code>, |
| 253 | then the function should send a single <a href="../api_reference/C/dbt.html" class="olink">DBT</a> in |
| 254 | response using the channel provided to this function, |
| 255 | and the <a href="../api_reference/C/dbchannel_send_msg.html" class="olink">DB_CHANNEL->send_msg()</a> method. |
| 256 | </p> |
| 257 | </li> |
| 258 | </ul> |
| 259 | </div> |
| 260 | <p> |
| 261 | For an example of using this callback, see the |
| 262 | <code class="literal">operation_dispatch()</code> function, which is |
| 263 | available with the <a class="link" href="rep_ex_chan.html" title="Ex_rep_chan: a Replication Manager channel example">ex_rep_chan example</a> |
| 264 | in your product distribution. |
| 265 | </p> |
| 266 | </div> |
| 267 | </div> |
| 268 | <div class="navfooter"> |
| 269 | <hr /> |
| 270 | <table width="100%" summary="Navigation footer"> |
| 271 | <tr> |
| 272 | <td width="40%" align="left"><a accesskey="p" href="rep_clock_skew.html">Prev</a> </td> |
| 273 | <td width="20%" align="center"> |
| 274 | <a accesskey="u" href="rep.html">Up</a> |
| 275 | </td> |
| 276 | <td width="40%" align="right"> <a accesskey="n" href="rep_twosite.html">Next</a></td> |
| 277 | </tr> |
| 278 | <tr> |
| 279 | <td width="40%" align="left" valign="top">Clock Skew </td> |
| 280 | <td width="20%" align="center"> |
| 281 | <a accesskey="h" href="index.html">Home</a> |
| 282 | </td> |
| 283 | <td width="40%" align="right" valign="top"> Special considerations for two-site replication groups</td> |
| 284 | </tr> |
| 285 | </table> |
| 286 | </div> |
| 287 | </body> |
| 288 | </html> |