#include #include #include #include #include std::ofstream outputFile("C:/Users/l0185/Desktop/nats-client-prattice/bin/Debug/publishMessage.txt"); void ThreadPublish(jsCtx*js,std::string subject,std::string Mess) { natsStatus s; jsPubAck *pa = NULL; int index = 0; if(!outputFile.is_open()){ std::cout<<"can't open the file"<Err, pae->ErrCode, pae->ErrText); printf("Original message: %.*s\n", natsMsg_GetDataLength(pae->Msg), natsMsg_GetData(pae->Msg)); *errors = (*errors + 1); // If we wanted to resend the original message, we would do something like that: // // js_PublishMsgAsync(js, &(pae->Msg), NULL); // // Note that we use `&(pae->Msg)` so that the library set it to NULL if it takes // ownership, and the library will not destroy the message when this callback returns. // No need to destroy anything, everything is handled by the library. } int main() { std::string errCode; natsConnection *conn = NULL; natsStatistics *stats = NULL; natsOptions *opts = NULL; jsCtx *js = NULL; jsOptions jsOpts; jsErrCode jerr ; natsStatus s; int dataLen=0; volatile int errors = 0; bool delStream = false; bool async = false; char * stream = "foostream"; char * durable = "foodurable"; const char ** subj=new const char *[3]; subj[0]="foo1"; subj[1]="foo2"; subj[2]="foo3"; s=natsOptions_Create(&opts); natsOptions_SetURL(opts,"nats://localhost:42342"); s = natsConnection_Connect(&conn, opts); if (s == NATS_OK) s = jsOptions_Init(&jsOpts); if (s == NATS_OK) { if (async) { jsOpts.PublishAsync.ErrHandler = _jsPubErr; jsOpts.PublishAsync.ErrHandlerClosure = (void*) &errors; } s = natsConnection_JetStream(&js, conn, &jsOpts); std::cout<<"natsConnection_JetStream OK"<Config->Name, si->State.Msgs, si->State.Bytes); // Need to destroy the returned stream object. jsStreamInfo_Destroy(si); } else { errCode = natsStatus_GetText(s); std::cout<<(int)s<<":"<>end; // Destroy all our objects to avoid report of memory leak jsCtx_Destroy(js); // natsStatistics_Destroy(stats); natsConnection_Destroy(conn); natsOptions_Destroy(opts); // To silence reports of memory still in used with valgrind nats_Close(); return 0; }