Skip to content

Commit

Permalink
added error test to SimpleProducer for connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidTompkins committed Dec 19, 2013
1 parent 716471d commit 67dee43
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions samples/SimpleProducer.cc
Expand Up @@ -27,6 +27,7 @@
#include <string>
#include <cstring>
#include <vector>
#include <errno.h>
#include <libkafka/ApiConstants.h>
#include <libkafka/Client.h>
#include <libkafka/Message.h>
Expand Down Expand Up @@ -62,13 +63,20 @@ main()

ProduceResponse *response = c->sendProduceRequest(request);

if (response->hasErrorCode())
cerr << "publish error detected\n";
if (response == NULL)
{
cerr << "an error ocurred while sending the produce request, errno = " << strerror(errno) << "\n";
}
else
cout << "message successfully published to kafka\n";
{
if (response->hasErrorCode())
cerr << "publish error detected\n";
else
cout << "message successfully published to kafka\n";
}

delete request;
delete response;
if (response != NULL) delete response;
}

// culled from high-level client (coming soon...)
Expand All @@ -87,7 +95,7 @@ Message* createMessage(const char * value, const char *key)

unsigned char *v = new unsigned char[strlen(value)];
memcpy(v, value, strlen(value));

unsigned char *k = new unsigned char[strlen(key)];
memcpy(k, key, strlen(key));

Expand Down

0 comments on commit 67dee43

Please sign in to comment.