Skip to content

A WordPress plugin for emitting AMQP messages for post create, update, and delete events.

License

Notifications You must be signed in to change notification settings

OutisNemo/wp-amqp-producer

Repository files navigation

WP AMQP Producer

A tiny WordPress plugin for emitting AMQP messages when a post is created, updated or deleted. The affected posts can be filtered by post_type property. It's been tested against RabbitMQ.

Requirements

This plugin utilizes the php-amqplib library which uses the bcmath and sockets PHP extension, so make sure these are available on your system. During the development we tested with WordPress 5.2.2 running on PHP 7.2 version.

Usage

This plugin has no graphical interface at all, the configuration options are taken from wp-config.php file. To get quickly started add the following lines to your config file and make sure that your RabbitMQ server is running and the configured exchange will be created automatically:

define('AMQP_URL', 'amqp://admin:admin@rabbitmq:5672');  
define('AMQP_EXCHANGE', 'sample-exchange');

Then upload the plugin in zip format (download here) or upload the files manually into /wp-contents/plugin/wp-amqp-producer directory and activate in the admin panel.

Now you can test the plugin by updating/creating any post and check if a message is emitted successfully.

Configuration options

Name Description Example value
AMQP_URL (Required) Connection URI which contains the host, port, username, password and vhost fields. amqp://admin:admin@rabbitmq
AMQP_EXCHANGE (Required) Exchange name which will accept the messages. sample-exchange
AMQP_DELIVERY_MODE (Optional) Delivery mode of the message, possible values are PERSISTENT or NON_PERSISTENT, default is PERSISTENT. PERSISTENT
AMQP_EXTRA_HEADERS (Optional) Header for each published message. Each header's key and value must be separated with the : string. If you want multiple headers to pass, separate them by newline. Default value is empty. content-type: application/json\nrbs2-content-type: application/json;charset=utf-8
AMQP_ALLOWED_TYPES (Optional) Allowed types for the WordPress save_post hook. The plugin will only emit message for the allowed post types. If you want to allow multiple post types, separate them by comma. Default is empty, all post type allowed. post,order
AMQP_OUTPUT_FIELDS (Optional) Specifies the generated properties of the emitted JSON message. You can specify multiple values separated by comma. Possible values are post, post_meta, author, current_user. Default value is post. post,current_user

Example message

Below you can find and example message which is posted to RabbitMQ after updating the default post on a fresh WordPress instance.

{
   "post":{
      "ID":1,
      "post_author":"1",
      "post_date":"2019-08-21 18:58:03",
      "post_date_gmt":"2019-08-21 18:58:03",
      "post_content":"<!-- wp:paragraph -->\n<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!<\/p>\n<!-- \/wp:paragraph -->",
      "post_title":"Hello world!",
      "post_excerpt":"",
      "post_status":"publish",
      "comment_status":"open",
      "ping_status":"open",
      "post_password":"",
      "post_name":"hello-world",
      "to_ping":"",
      "pinged":"",
      "post_modified":"2019-08-22 16:35:26",
      "post_modified_gmt":"2019-08-22 16:35:26",
      "post_content_filtered":"",
      "post_parent":0,
      "guid":"http:\/\/127.0.0.1\/?p=1",
      "menu_order":0,
      "post_type":"post",
      "post_mime_type":"",
      "comment_count":"1",
      "filter":"raw"
   },
   "post_meta":{
      "_edit_lock":{
         "0":"1566491701:1"
      },
      "_pingme":{
         "0":"1"
      },
      "_encloseme":{
         "0":"1"
      }
   },
   "author":null,
   "current_user":null
}

Contributing

Contributions are welcome and will be fully credited.

We accept contributions via Pull Requests on GitHub.

About

A WordPress plugin for emitting AMQP messages for post create, update, and delete events.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages