diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -29,3 +29,7 @@
   M.destroyMosquitto m
   print "The end"
 ```
+
+# Hacking
+
+Documentation for used C library can be found at <https://mosquitto.org/api/files/mosquitto-h.html>.
diff --git a/c-mosquitto.cabal b/c-mosquitto.cabal
--- a/c-mosquitto.cabal
+++ b/c-mosquitto.cabal
@@ -1,5 +1,5 @@
 name:                c-mosquitto
-version:             0.1.4.0
+version:             0.1.4.1
 synopsis:            Simpe mosquito MQTT binding able to work with the Amazons IoT
 -- description:
 homepage:            https://github.com/tolysz/c-mosquitto#readme
diff --git a/src/Network/Mosquitto.hs b/src/Network/Mosquitto.hs
--- a/src/Network/Mosquitto.hs
+++ b/src/Network/Mosquitto.hs
@@ -101,10 +101,10 @@
                                 )
        }|]
 
-setReconnectDelay 
+setReconnectDelay
   :: Mosquitto a -- ^ mosquitto instance
   -> Bool        -- ^ exponential backoff
-  -> Int         -- ^ initial backoff 
+  -> Int         -- ^ initial backoff
   -> Int         -- ^ maximum backoff
   -> IO Int
 setReconnectDelay mosq  exponential (fromIntegral -> reconnectDelay) (fromIntegral -> reconnectDelayMax) =
@@ -183,6 +183,17 @@
         mosquitto_message_callback_set
             ( $(struct mosquitto *pMosq)
             , $(void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *))
+            );
+       }|]
+
+onPublish :: Mosquitto a -> OnPublish -> IO ()
+onPublish mosq onPublish =  do
+  on_publish <- mkCOnPublish $ \_ _ mid -> onPublish (fromIntegral mid)
+  withPtr mosq $ \pMosq ->
+     [C.block|void{
+        mosquitto_publish_callback_set
+            ( $(struct mosquitto *pMosq)
+            , $(void (*on_publish)(struct mosquitto *,void *, int))
             );
        }|]
 
diff --git a/src/Network/Mosquitto/Internal/Types.hs b/src/Network/Mosquitto/Internal/Types.hs
--- a/src/Network/Mosquitto/Internal/Types.hs
+++ b/src/Network/Mosquitto/Internal/Types.hs
@@ -69,3 +69,8 @@
 type COnSubscribe = Ptr C'Mosquitto ->  Ptr () -> CInt -> CInt -> Ptr CInt -> IO ()
 foreign import ccall "wrapper"
   mkCOnSubscribe :: COnSubscribe -> IO (FunPtr COnSubscribe)
+
+type OnPublish = Int -> IO ()
+type COnPublish = Ptr C'Mosquitto -> Ptr () -> CInt -> IO ()
+foreign import ccall "wrapper"
+  mkCOnPublish :: COnPublish -> IO (FunPtr COnPublish)
