pkoretic / qt-nats Goto Github PK
View Code? Open in Web Editor NEWA C++11 nats client written in Qt
License: GNU Lesser General Public License v3.0
A C++11 nats client written in Qt
License: GNU Lesser General Public License v3.0
Hi, I found that You missed brackets in file natsclient.h, line 499
Now is:
while(last_pos != buffer.toUtf8.length())
should be:
while(last_pos != buffer.toUtf8().length())
In file included from main.cpp:3:
./../../natsclient.h:248:55: error: no member named 'errorOccurred' in 'QAbstractSocket'
QObject::connect(&m_socket, &QAbstractSocket::errorOccurred, this, [this](QAbstractSocket::SocketError socketError)
~~~~~~~~~~~~~~~~~^
./../../natsclient.h:347:56: error: no member named 'errorOccurred' in 'QAbstractSocket'
QObject::connect(&m_socket, &QAbstractSocket::errorOccurred, this, [this](QAbstractSocket::SocketError socketError)
~~~~~~~~~~~~~~~~~^
./../../natsclient.h:587:63: error: no member named 'split' in 'QStringView'
QList parts = QStringView{operation}.split(u" ", Qt::SkipEmptyParts);
~~~~~~~~~~~~~~~~~~~~~~ ^
./../../natsclient.h:587:79: error: no member named 'SkipEmptyParts' in namespace 'Qt'
QList parts = QStringView{operation}.split(u" ", Qt::SkipEmptyParts);
~~~~^
./../../natsclient.h:593:40: error: no member named 'toInt' in 'QStringView'
message_len = parts[3].toInt();
~~~~~~~~ ^
./../../natsclient.h:598:40: error: no member named 'toInt' in 'QStringView'
message_len = parts[4].toInt();
~~~~~~~~ ^
4 warnings and 6 errors generated.
make: *** [main.o] Error 1
I try to install nl.cqm.Qt5Core on Nuget packages manager
https://www.nuget.org/packages/nl.cqm.Qt5Core/5.9.6/
but don't have file QSslConfiguration.h and QSslSocket.h in natsclient.h
#include <QSslConfiguration.h> #include <QSslSocket.h>
Greetings,
Please review the parsing code i've written and consider adopting it for this project.
https://gist.github.com/Think7/f1f73bb4afc62fee472c8efc25175498
I've written some notes / explanation at the top and tried to add helpful comments throughout.
Hello, I found error in client publish method (C++ qt5) when I used Russian letters. So, I also found the answer to solve it. Please, fix it in official version. I just corrected the publish method in "natsclient.h". Right way is here:
inline void Client::publish(const QString &subject, const QString &message, const QString &inbox)
{
QString body = QStringLiteral("PUB ") % subject % " " % inbox % (inbox.isEmpty() ? "" : " ") % QString::number(message.toUtf8().length()) % CLRF % message % CLRF;
DEBUG("published:" << body);
m_socket.write(body.toUtf8());
}
It's forgotten to set Utf8 before setting the length().
Bad way is:
QString::number(message.length())
Right is:
QString::number(message.toUtf8().length())
please add #include to natsclient.h
Tested at Qt5.7 and mingw
hi,
i want to publish && subscribe byteArray data, how can i do?
Should be:
if(current_pos + message_len + CLRF.length() > buffer.toUtf8().length())
{
DEBUG("message not in buffer, waiting");
break;
}
Hi,
By glancing at the sources I noticed that qt-nats has no cluster awareness like the official Synadia C client (no server list, no automatic reconnects etc).
Form nats.c, Clustered usage:
static char *servers[] = { "nats://localhost:1222",
"nats://localhost:1223",
"nats://localhost:1224"};
// Setup options to include all servers in the cluster.
// We first created an options object, and pass the list of servers, specifying
// the number of servers on that list.
natsOptions_SetServers(opts, servers, 3);
// We could also set the amount to sleep between each reconnect attempt (expressed in
// milliseconds), and the number of reconnect attempts.
natsOptions_SetMaxReconnect(opts, 5);
natsOptions_SetReconnectWait(opts, 2000);
// We could also disable the randomization of the server pool
natsOptions_SetNoRandomize(opts, true);
// Setup a callback to be notified on disconnects...
natsOptions_SetDisconnectedCB(opts, disconnectedCb, NULL);
// And on reconncet
natsOptions_SetReconnectedCB(opts, reconnectedCb, NULL);
// This callback could be used to see who we are connected to on reconnect
static void
reconnectedCb(natsConnection *nc, void *closure)
{
// Define a buffer to receive the url
char buffer[64];
buffer[0] = '\0';
natsConnection_GetConnectedUrl(nc, buffer, sizeof(buffer));
printf("Got reconnected to: %s\n", buffer);
}
This prompted me to ask:
a) How compatible is nats-qt with current nats-server versions (eg. v2.0.4) ?
b) Would @pkoretic be willing to add the missing functionality to qt-nats?
Anyway, thank you for sharing the code. Great little lib!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.