Skip to content

Commit

Permalink
rabbitmq: cleanup obsolete connection parameters
Browse files Browse the repository at this point in the history
REVERT ME if you really need the old module parameters and are not able to update to 'url'.
  • Loading branch information
Stefan Mititelu committed Mar 9, 2017
1 parent 498b5c7 commit 2812b69
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 235 deletions.
123 changes: 23 additions & 100 deletions src/modules/rabbitmq/README
Expand Up @@ -26,14 +26,9 @@ Stefan-Cristian Mititelu
3. Parameters

3.1. url (string)
3.2. username (string)
3.3. password (string)
3.4. host (string)
3.5. vhost (string)
3.6. port (int)
3.7. timeout_sec (int)
3.8. timeout_usec (int)
3.9. direct_reply_to (int)
3.2. timeout_sec (int)
3.3. timeout_usec (int)
3.4. direct_reply_to (int)

4. Functions

Expand All @@ -46,16 +41,11 @@ Stefan-Cristian Mititelu
List of Examples

1.1. Set the “url” parameter
1.2. Set the “username” parameter
1.3. Set the “password” parameter
1.4. Set the “host” parameter
1.5. Set the “vhost” parameter
1.6. Set the “port” parameter
1.7. Set the “timeout_sec” parameter
1.8. Set the “timeout_usec” parameter
1.9. Set the “direct_reply_to” parameter
1.10. rabbitmq_publish usage
1.11. rabbitmq_publish_consume usage
1.2. Set the “timeout_sec” parameter
1.3. Set the “timeout_usec” parameter
1.4. Set the “direct_reply_to” parameter
1.5. rabbitmq_publish usage
1.6. rabbitmq_publish_consume usage

Chapter 1. Admin Guide

Expand All @@ -70,14 +60,9 @@ Chapter 1. Admin Guide
3. Parameters

3.1. url (string)
3.2. username (string)
3.3. password (string)
3.4. host (string)
3.5. vhost (string)
3.6. port (int)
3.7. timeout_sec (int)
3.8. timeout_usec (int)
3.9. direct_reply_to (int)
3.2. timeout_sec (int)
3.3. timeout_usec (int)
3.4. direct_reply_to (int)

4. Functions

Expand Down Expand Up @@ -118,20 +103,13 @@ Chapter 1. Admin Guide
3. Parameters

3.1. url (string)
3.2. username (string)
3.3. password (string)
3.4. host (string)
3.5. vhost (string)
3.6. port (int)
3.7. timeout_sec (int)
3.8. timeout_usec (int)
3.9. direct_reply_to (int)
3.2. timeout_sec (int)
3.3. timeout_usec (int)
3.4. direct_reply_to (int)

3.1. url (string)

The amqp connection url. If set to something else than the default
value, it will overwrite the values of all connection parameters below
(e.g. username, password, host, vhost, port)
The amqp connection url.

Default value is “amqp://guest:guest@localhost:5672/%2F”.

Expand All @@ -141,96 +119,41 @@ modparam("rabbitmq", "url", "amqp://kamailio:kamailio@localhost:5672/%2Fkamailio
")
...

3.2. username (string)

The user name of amqp connection.

Default value is “"guest"”.

Example 1.2. Set the “username” parameter
...
modparam("rabbitmq", "username", "user")
...

3.3. password (string)

The password of amqp connection.

Default value is “"guest"”.

Example 1.3. Set the “password” parameter
...
modparam("rabbitmq", "password", "pass")
...

3.4. host (string)

The host of amqp connection.

Default value is “"localhost"”.

Example 1.4. Set the “host” parameter
...
modparam("rabbitmq", "host", "127.0.0.1")
...

3.5. vhost (string)

The vhost of the amqp connection.

Default value is “"/"”.

Example 1.5. Set the “vhost” parameter
...
modparam("rabbitmq", "vhost", "/vhost")
...

3.6. port (int)

The port of the amqp connection.

Default value is “5672”.

Example 1.6. Set the “port” parameter
...
modparam("rabbitmq", "port", 5672)
...

3.7. timeout_sec (int)
3.2. timeout_sec (int)

The timeout in seconds. The timeout_sec + timeout_usec combination
gives the time to wait for an amqp reply, when
rabbitmq_publish_consume() is used.

Default value is “1”.

Example 1.7. Set the “timeout_sec” parameter
Example 1.2. Set the “timeout_sec” parameter
...
modparam("rabbitmq", "timeout_sec", 1)
...

3.8. timeout_usec (int)
3.3. timeout_usec (int)

The timeout in micro seconds. The timeout_sec + timeout_usec
combination gives the time to wait for an amqp reply, when
rabbitmq_publish_consume() is used.

Default value is “0”.

Example 1.8. Set the “timeout_usec” parameter
Example 1.3. Set the “timeout_usec” parameter
...
modparam("rabbitmq", "timeout_usec", 0)
...

3.9. direct_reply_to (int)
3.4. direct_reply_to (int)

Setting this parameter to 1, enables rabbitmq direct reply-to feature.
More info about this, can be found at
https://www.rabbitmq.com/direct-reply-to.html.

Default value is “0”.

Example 1.9. Set the “direct_reply_to” parameter
Example 1.4. Set the “direct_reply_to” parameter
...
modparam("rabbitmq", "direct_reply_to", 1)
...
Expand All @@ -254,7 +177,7 @@ modparam("rabbitmq", "direct_reply_to", 1)

This function can be used from REQUEST_ROUTE.

Example 1.10. rabbitmq_publish usage
Example 1.5. rabbitmq_publish usage
rabbitmq_publish("exchange", "routing_key", "application/json", "$avp(json_reque
st)");

Expand All @@ -274,6 +197,6 @@ messagebody, reply)

This function can be used from REQUEST_ROUTE.

Example 1.11. rabbitmq_publish_consume usage
Example 1.6. rabbitmq_publish_consume usage
rabbitmq_publish_consume("exchange", "routing_key", "application/json", "$avp(js
on_request)", "$avp(json_reply)");
111 changes: 0 additions & 111 deletions src/modules/rabbitmq/doc/rabbitmq_admin.xml
Expand Up @@ -75,7 +75,6 @@
<title><varname>url</varname> (string)</title>
<para>
The amqp connection url.
If set to something else than the default value, it will overwrite the values of all connection parameters below (e.g. username, password, host, vhost, port)
</para>

<para>
Expand All @@ -94,116 +93,6 @@ modparam("rabbitmq", "url", "amqp://kamailio:kamailio@localhost:5672/%2Fkamailio
</example>
</section>

<section id="rabbitmq.p.username">
<title><varname>username</varname> (string)</title>
<para>
The user name of amqp connection.
</para>

<para>
<emphasis>
Default value is <quote>"guest"</quote>.
</emphasis>
</para>

<example>
<title>Set the <quote>username</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("rabbitmq", "username", "user")
...
</programlisting>
</example>
</section>

<section id="rabbitmq.p.password">
<title><varname>password</varname> (string)</title>
<para>
The password of amqp connection.
</para>

<para>
<emphasis>
Default value is <quote>"guest"</quote>.
</emphasis>
</para>

<example>
<title>Set the <quote>password</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("rabbitmq", "password", "pass")
...
</programlisting>
</example>
</section>

<section id="rabbitmq.p.host">
<title><varname>host</varname> (string)</title>
<para>
The host of amqp connection.
</para>

<para>
<emphasis>
Default value is <quote>"localhost"</quote>.
</emphasis>
</para>

<example>
<title>Set the <quote>host</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("rabbitmq", "host", "127.0.0.1")
...
</programlisting>
</example>
</section>

<section id="rabbitmq.p.vhost">
<title><varname>vhost</varname> (string)</title>
<para>
The vhost of the amqp connection.
</para>

<para>
<emphasis>
Default value is <quote>"/"</quote>.
</emphasis>
</para>

<example>
<title>Set the <quote>vhost</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("rabbitmq", "vhost", "/vhost")
...
</programlisting>
</example>
</section>

<section id="rabbitmq.p.port">
<title><varname>port</varname> (int)</title>
<para>
The port of the amqp connection.
</para>

<para>
<emphasis>
Default value is <quote>5672</quote>.
</emphasis>
</para>

<example>
<title>Set the <quote>port</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("rabbitmq", "port", 5672)
...
</programlisting>
</example>
</section>

<section id="rabbitmq.p.timeout_sec">
<title><varname>timeout_sec</varname> (int)</title>
<para>
Expand Down
31 changes: 7 additions & 24 deletions src/modules/rabbitmq/rabbitmq.c
Expand Up @@ -72,11 +72,6 @@ amqp_connection_state_t conn = NULL;
/* module parameters */
struct amqp_connection_info amqp_info;
char *amqp_url = RABBITMQ_DEFAULT_AMQP_URL;
char *amqp_username = "guest";
char *amqp_password = "guest";
char *amqp_host = "localhost";
char *amqp_vhost = "/";
int amqp_port = 5672;
int max_reconnect_attempts = 1;
int timeout_sec = 1;
int timeout_usec = 0;
Expand Down Expand Up @@ -128,11 +123,6 @@ static cmd_export_t cmds[] = {
/* module parameters */
static param_export_t params[] = {
{"url", PARAM_STRING, &amqp_url},
{"username", PARAM_STRING, &amqp_username},
{"password", PARAM_STRING, &amqp_password},
{"host", PARAM_STRING, &amqp_host},
{"vhost", PARAM_STRING, &amqp_vhost},
{"port", PARAM_INT, &amqp_port},
{"timeout_sec", PARAM_INT, &timeout_sec},
{"timeout_usec", PARAM_INT, &timeout_usec},
{"direct_reply_to", PARAM_INT, &direct_reply_to},
Expand All @@ -155,18 +145,11 @@ struct module_exports exports = {
/* module init */
static int mod_init(void)
{
if (strcmp(amqp_url, RABBITMQ_DEFAULT_AMQP_URL)) {
if (amqp_parse_url(amqp_url, &amqp_info) == AMQP_STATUS_BAD_URL) {
LM_ERR("FAIL parsing url: '%s'\n", amqp_url);
return -1;
} else {
LM_INFO("SUCCESS parsing url: '%s'\n", amqp_url);
amqp_username = amqp_info.user;
amqp_password = amqp_info.password;
amqp_host = amqp_info.host;
amqp_vhost = amqp_info.vhost;
amqp_port = amqp_info.port;
}
if (amqp_parse_url(amqp_url, &amqp_info) == AMQP_STATUS_BAD_URL) {
LM_ERR("FAIL parsing url: '%s'\n", amqp_url);
return -1;
} else {
LM_INFO("SUCCESS parsing url: '%s'\n", amqp_url);
}

return 0;
Expand Down Expand Up @@ -539,14 +522,14 @@ static int rabbitmq_connect(amqp_connection_state_t *conn) {
return RABBITMQ_ERR_SOCK;
}

ret = amqp_socket_open(amqp_sock, amqp_host, amqp_port);
ret = amqp_socket_open(amqp_sock, amqp_info.host, amqp_info.port);
if (ret != AMQP_STATUS_OK) {
LM_ERR("FAIL: open TCP sock, amqp_status=%d", ret);
// amqp_destroy_connection(*conn);
return RABBITMQ_ERR_SOCK;
}

log_ret = log_on_amqp_error(amqp_login(*conn, amqp_vhost, 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, amqp_username, amqp_password), "amqp_login()");
log_ret = log_on_amqp_error(amqp_login(*conn, amqp_info.vhost, 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, amqp_info.user, amqp_info.password), "amqp_login()");
if (log_ret != AMQP_RESPONSE_NORMAL && log_ret != AMQP_RESPONSE_NONE) {
LM_ERR("FAIL: amqp_login()\n");
// amqp_destroy_connection(*conn);
Expand Down

0 comments on commit 2812b69

Please sign in to comment.