Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Invoke PubNub PUSH Message via MySQL Trigger on UPDATE, INSERT and DELETE</h1> <blockquote> <p>⚠️ <strong>Warring!</strong> this may cause slowdowns on your database. This will introduce relatively poor performance given sys exec'ing curl for every insert. Far better to also have a trigger write the message to another table and have another process checking for new rows in a loop.</p> </blockquote> <p>MySQL Makes it simple to wrap your coding into easily accessible <strong>TRIGGERS</strong> via Stored Procedures. You can create something similar with pusher and I know how to do it with PubNub; so here is a quick guide with PubNub and MySQL. Simplicity is what you seek and here is your solution! I will walk you through an easy way to bind any <strong>UPDATE</strong>, <strong>INSERT</strong> and <strong>DELETE</strong> action on your table to a stored function that will get invoked each time, sending a push notifications to your mobile and web apps easily with PubNub.</p> <h2>PubNub Push Message</h2> <pre><code>DELIMITER $$ CREATE PROCEDURE push_message (p1 DOUBLE, p2 DOUBLE, p3 BIGINT) BEGIN DECLARE cmd CHAR(255); DECLARE result CHAR(255); SET cmd = CONCAT('curl https://pubsub.pubnub.com/publish/demo/demo/0/mysql_triggers/0/%22',p1, ',' ,p2, ',' ,p3,'%22'); SET result = sys_eval(cmd); END$$; </code></pre> <p><em>NOTE: Make sure your PROCEDURE types are correct <strong>DOUBLE</strong> or <strong>VARCHAR</strong> or <strong>TEXT</strong>.</em></p> <h2>MySQL Trigger Code INSERT Example</h2> <pre><code>CREATE TRIGGER push_message_trigger AFTER INSERT ON your_table_name_here FOR EACH ROW CALL push_message(NEW.Column1, NEW.Column2, NEW.Column3); </code></pre> <p><em>NOTE: Make sure to include the columns you need here in your push message.</em></p> <h2>MySQL Trigger Code UPDATE Example</h2> <pre><code>CREATE TRIGGER push_message_trigger AFTER UPDATE ON your_table_name_here FOR EACH ROW CALL push_message(NEW.Column1, NEW.Column2, NEW.Column3); </code></pre> <h2>Monitor the Push Message via Debug Console</h2> <p><a href="http://www.pubnub.com/console?sub=demo&amp;pub=demo&amp;channel=mysql_triggers" rel="noreferrer">http://www.pubnub.com/console?sub=demo&amp;pub=demo&amp;channel=mysql_triggers</a> - You can watch your triggers being fired via PubNub Dev Console. This way you can understand what paramaters you need to have changed and what data is important for you to include in each push notifications that can be received by PubNub websocket and more on the Mobile and Web device.</p> <h2>Receiving The Push Message in JavaScript</h2> <pre><code>&lt;div id=pubnub ssl=on&gt;&lt;/div&gt; &lt;script src=//pubnub.a.ssl.fastly.net/pubnub-3.4.5.min.js&gt;&lt;/script&gt; &lt;script&gt;(function(){ PUBNUB.init({ subscribe_key : 'demo', ssl : true }).subscribe({ channel : 'mysql_triggers', callback : function(mysql_trigger_details) { alert(mysql_trigger_details); } }); })();&lt;/script&gt; </code></pre> <p>Now you have the steps needed to send and receive <strong>change events</strong> from MySQL directly via simple procedures. There are ways to optimize this method as well such as issuing a signal to a daemon process that queues and pools HTTPS push notifications. This should be plenty efficient.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload