The best freely available arduino library is the one from knolleary.


Simple example code could then look like:

            
                #include <SPI.h>
                #include <PubSubClient.h>
                #include <Ethernet.h>

                EthernetClient client;
                PubSubClient arduinoClient(hostname, port, callback, client);



                void setup() {
                   Serial.begin(9600);
                   beginConnection();
                }

                void beginConnection(){
                   if (Ethernet.begin(yourMACaddress) == 0) {
                      Serial.println(F("Failed to configure Ethernet using DHCP"));
                      exit(-1);
                   };

                   // Connect, use NULL as client id to let the server generate one
                   if (arduinoClient.connect(NULL,yourUserName,yourPassword)) {
                      // Subscribe
                      if (not(arduinoClient.subscribe(yourRootTopic))) exit(-1);
                   } else {
                      Serial.println(F("Failed to connect to the MQTT Server"));
                      exit(-1);
                   }
                }

                void loop() {
                   if (not(arduinoClient.loop())){
                      // here your should try to reconnect & re-subscribe
                   }
                   // Publish
                   arduinoClient.publish(yourRootTopic, "Hello World Message!");
                }