Merge pull request #1996 from greenbea/amqp_subclass_support

[mod_amqp] Event subclass support
This commit is contained in:
Andrey Volk 2023-03-27 19:55:46 +03:00 committed by GitHub
commit 49eb8a77ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -87,6 +87,11 @@ typedef struct mod_amqp_keypart_s {
int size; int size;
} mod_amqp_keypart_t; } mod_amqp_keypart_t;
typedef struct {
switch_event_types_t id;
char* subclass;
} mod_amqp_events_t;
typedef struct { typedef struct {
char *name; char *name;
@ -103,7 +108,7 @@ typedef struct {
/* Array to store the possible event subscriptions */ /* Array to store the possible event subscriptions */
int event_subscriptions; int event_subscriptions;
switch_event_node_t *event_nodes[SWITCH_EVENT_ALL]; switch_event_node_t *event_nodes[SWITCH_EVENT_ALL];
switch_event_types_t event_ids[SWITCH_EVENT_ALL]; mod_amqp_events_t events[SWITCH_EVENT_ALL];
switch_event_node_t *eventNode; switch_event_node_t *eventNode;

View File

@ -186,7 +186,8 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg)
profile->name = switch_core_strdup(profile->pool, name); profile->name = switch_core_strdup(profile->pool, name);
profile->running = 1; profile->running = 1;
memset(profile->format_fields, 0, (MAX_ROUTING_KEY_FORMAT_FIELDS + 1) * sizeof(mod_amqp_keypart_t)); memset(profile->format_fields, 0, (MAX_ROUTING_KEY_FORMAT_FIELDS + 1) * sizeof(mod_amqp_keypart_t));
profile->event_ids[0] = SWITCH_EVENT_ALL; profile->events[0].id = SWITCH_EVENT_ALL;
profile->events[0].subclass = SWITCH_EVENT_SUBCLASS_ANY;
profile->event_subscriptions = 1; profile->event_subscriptions = 1;
profile->conn_root = NULL; profile->conn_root = NULL;
profile->conn_active = NULL; profile->conn_active = NULL;
@ -269,7 +270,14 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Found %d subscriptions\n", profile->event_subscriptions); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Found %d subscriptions\n", profile->event_subscriptions);
for (arg = 0; arg < profile->event_subscriptions; arg++) { for (arg = 0; arg < profile->event_subscriptions; arg++) {
if (switch_name_event(argv[arg], &(profile->event_ids[arg])) != SWITCH_STATUS_SUCCESS) { char *subclass = SWITCH_EVENT_SUBCLASS_ANY;
if ((subclass = strchr(argv[arg], '^'))) {
*subclass++ = '\0';
}
if (switch_name_event(argv[arg], &(profile->events[arg].id)) == SWITCH_STATUS_SUCCESS) {
profile->events[arg].subclass = subclass;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The switch event %s was not recognised.\n", argv[arg]); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The switch event %s was not recognised.\n", argv[arg]);
} }
} }
@ -344,13 +352,13 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg)
/* Subscribe events */ /* Subscribe events */
for (i = 0; i < profile->event_subscriptions; i++) { for (i = 0; i < profile->event_subscriptions; i++) {
if (switch_event_bind_removable("AMQP", if (switch_event_bind_removable("AMQP",
profile->event_ids[i], profile->events[i].id,
SWITCH_EVENT_SUBCLASS_ANY, profile->events[i].subclass,
mod_amqp_producer_event_handler, mod_amqp_producer_event_handler,
profile, profile,
&(profile->event_nodes[i])) != SWITCH_STATUS_SUCCESS) { &(profile->event_nodes[i])) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind to event handler %d!\n",(int)profile->event_ids[i]); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind to event handler %d!\n",(int)profile->events[i].id);
goto err; goto err;
} }
} }