Camel PAHO routes not receiving offline messages while connecting back - apache-camel

I'm using apache camel xml based paho routes for the subscription, publication process. While online, everything works fine. But I'm not able to receive the offline message.
I have set the following.,
Constant Client ID
Clean Session is FALSE,
Both subscribed & published with QoS 2
With the standalone Program, it's getting all the offline messages. With the camel route it's not happening.

Finally, I was able to solve this one manually.
Camel PAHO Client is not populating the callback function before performing the broker connection. They are doing it only when the connection is made.
So, once the connection is success then the broker just sends all the offline messages. In this case, our client does not have callback handlers to handle these messages. So they are lost.
Other clients (IoThub Client) which uses the PAHO internally is doing it right by setting the callback and initiating the connection.

Related

How do I refresh the token in a cometd client talking to a Salesforce Platform EventBus?

I'm using cometd to listen to platform events generated in Salesforce. My cometd client configuration code looks like
this.client.configure({
url: `${this.org.instance_url}/cometd/46.0`,
requestHeaders: {
Authorization: `Bearer ${salesforceToken}`
},
appendMessageTypeToURL: false
});
where the salesforceToken is obtained using the refresh token. This all works fine for a while but if there are no events for a considerable period of time (anecdotally anywhere between 6-24 hours), then my client seems to expire and no events are received. If I refresh the token and restart my listener, things start working again.
Is there a way to keep the listener active other than writing some sort of timer to restart the process every few hours after inactivity ?
You do not have to refresh the token again
Whenever there is no activity on the channel, the server closes the connection after a specific time.
In that time client receives a 403 (Unknown client) status code, and the client has to handshake again withing 110 seconds.
By default, CometD tries to reconnect without any user interaction and If the client doesn't reconnect within the expected time, the server removes the client's CometD session.
Once the connection gets reconnect, all the channel subscriptions will be removed by ComedD, and we have to subscribe to the channel again in order to receive events.
In order to do so, we have to make use of meta/Handshake callback to resubscribe to the channel again.
see https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/using_streaming_api_client_connection.htm, paragraph "After Invalid Authentication"
"Streaming API regularly validates the OAuth token or session ID while the client is connected. If client authentication is not valid, the client is notified with the 401::Authentication invalid error and an advice field containing reconnect=none. After receiving the error notification in the channel listener, the client must reauthenticate and reconnect to receive new events."

Apache camel graceful route shutdown

I have a Camel route which Consumes messages from a Queue and stores the message into a Database. Now I wanted to shut down running camel route manually in a graceful manner. I have a RestEndpoint to be triggered whenever I need to stop Camel route. This endpoint should stop the route. But if there is any in-flight message or transaction running during the shutdown it has to be completed successfully without consuming any new messages from from("") endpoint of camel route and shut down after completing inflight message or transaction. Can anyone help me how Can I code this?
Below are the few options to control/monitor camel routes
CamelContext API's
Control bus component
JMX API's
You can go through below two sites to get started
http://camel.apache.org/controlbus.html
https://dzone.com/articles/apache-camel-monitoring
shutdownRunningTask(ShutdownRunningTask.CompleteCurrentTaskOnly)

Gets multiple events call back from angular end socket.io

(X) First Scenario
We have a web application and we are using socket.io as middleware. There is an angular end and there are API from .net. and it is a chat application, when a user sends a message it calls for the socket server and from socket server, we call to the API and we send the message to the particular socket. but when we send the message to the client the client event gets called multiple times(not every time but sometimes) from the angular end but the message, we have only sent once from the server(we set a logger to confirm this from server end). We have Azure Linux server. We are pooling socket ids from user ids as rooms. Though we removed rooms and added a manual array to pool sockets ids from user ids issue still exists. Working fine on android and ios devices.
****Second scenario
when we disconnect internet connection and reconnect the connection gets to connect to the server and we send a message after that it does send the message to other ends, but if we are sending messages from other end, messages are not coming to this end, from loggers in a server it shows that messages are sent. to the particular socket ids.
Setup
socket.io version: V2.0.3
node 6.11.4

Hotmail/Outlook.com connection failure on AUTH commands

I'm working on an embedded application (running MQX RTOS, written in C) which has SMTP functionality. Recently, TLS support was added using the Mocana NanoSSL library. I'm currently able to successfully send emails using Gmail, Yahoo, and private exchange servers. Unfortunately, Hotmail does not work. Here's the connection parameters i've used:
Server: smtp.live.com
Port: 25 and 587
AUTH method: PLAIN and LOGIN
Basically, i'm able to successfully connect to the server, perform the SSL/TLS handshake (using STARTTLS), and send the encrypted EHLO message to the server (receiving a response). According to this response, the server supports both AUTH PLAIN and AUTH LOGIN. However, once I send either of these commands, the following SSL_recv() call I make to get the response fails with either a timeout or connection reset by peer.
UPDATE:
OK, so after some experimentation it would appear that my issue lies at the SSL library level and not with Microsoft's SMTP server. I tried replacing the SSL_recv() calls with standard RTCS socket recv() calls and was able to receive and view encrypted data. By disabling my response verification, I was then able to continue through the SMTP process and successfully send a message. At this time i'm not sure why the SSL_recv() calls are unable to get the socket data, but i'll keep digging and will hopefully find an answer.
Well, I also got it working here too. I had to replace the
ssl_ctx=SSL_CTX_new(SSLv23_client_method());
with either:
ssl_ctx=SSL_CTX_new(SSLv3_client_method());
or
ssl_ctx=SSL_CTX_new(TLSv1_client_method());
My understanding is that the 23_client method sends a SSL2 client hello first and this confuses the server.
I read this in the HP SSL programming tutorial:
http://h71000.www7.hp.com/doc/83final/ba554_90007/ch04s03.html
it says: "However, the SSL client using the SSLv23 method cannot establish connection with the SSL server with the SSLv3/TLSv1 method because SSLv2 hello message is sent by the client."
SSL3 works too since you can continue after STARTTLS with SSL, you do not have to use TLS.
See here:
https://www.fastmail.fm/help/technology_ssl_vs_tls_starttls.html
So, it's the SSL library itself that appears to be failing me here. I was able to bypass the issue and successfully send email by simply not calling SSL_recv() to verify the server responses. I'm obviously not able to error check or get any meaningful failure feedback, but for a successful use case where the server accepts all of my SMTP messages the email is sent.

Configuring Apache Client timeout in apache module

I am writing an apache module and I am wondering how to handle the case where my ap_rwrite tries to write something back to the client and the client does not respond to it.
Does the call to ap_rwrite block until that happens?
Can I set a timeout on that? If so, what is it called?
Thanks!
The client does not respond to server again. HTTP is a request-response protocol, the client send a request to the server and server sends a response to client. Client should not respond to server.
If you mean how to know if the client receives the response maybe you can alter the default timeout, but if the socket is closed or other network error, the function 'ap_rwrite' will notice you with an error.

Resources