only 3 thread to access spring service layer at a time while keeping other request in buffer - spring

We have an utility for sending an email to customers. Currently we are using outlook for sending an emails, But once we send multiple email at a time we get the following error msg.
DEBUG SMTP: MessagingException while sending
com.sun.mail.smtp.SMTPSendFailedException: 432 4.3.2 STOREDRV.ClientSubmit; sender thread limit exceeded
After debugging its found that we can't send 3 mails at a time. So thought another approach to send msgs by queuing the request and process the 3 request at a time while keeping other in buffer.
Note: Don't want to use any msq queuing service (like rabbitMQ etc)
Your suggests/inputs will be really helpful for me.
Thanks

If you are using MS Office SMTP (I guess from the error message), there is a limit on concurrent connection.
Documentation
Under the new limit, up to three concurrent connections are allowed to send email messages at the same time.

Related

Laravel Queues PDO Connection not allowed

We have an sms job that gets fired for each sms that needs to be sent, so if we have 100 sms we schedule 100 jobs to allow for single and multiple sms's.
When we send the sms campaign it uses a 3rd party rest service to send the sms's, we sent a campaign of 7500 sms's, so there are 7500 jobs in the queue as soon as it sent 151 sms's we start getting
[2020-10-28 15:41:16] production.ERROR: Serialization of 'Doctrine\DBAL\Driver\PDOConnection' is not allowed {"exception":"[object] (Exception(code: 0): Serialization of 'Doctrine\DBAL\Driver\PDOConnection' is not allowed at /home/site/releases/20201026103626/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:139)
for all the rest of the sms's Not sure why this is happening.
We use laravel queues with the database (mysql) connection, all the rest of the sites on that server works fine, does not seem to lose connection to the database (when browsing the site while the queues are running) The database server is a separate server dedicated for mysql.
The problem is gone, there was alot of code for checking what time it is and only allow sending of sms's between certain times and other code i removed it and only left the actual sending of sms code and now everything went through perfectly maybe there was some issue in the other code that caused this.

Websockets: One handler to rule them all? Best case w/ backups?

I'm working on making an iOS app that does a few things, some of which would benefit from real-time data streams (like chat)
For right now I have a few handlers on my server, one of them gets all the threads a user has access to, another can get messages (offset, all, time-ranged, etc.) for a thread. When a user sends a message to a thread, I get all the listeners for the thread and send them a push notification. This works, but I was reading through the APNS docs and it says "dont do more than 3/hr" and I'm definitely doing more than 3/hr.
So I'm thinking I move to websockets. I know how to synchronize pub/subs across machines via redis so I'm not worried about that, I'm more stuck on the following:
If I start to bring websockets into the project, should I just pump all the information App <-> Server through the websocket? Create a thread -> Don't POST, just send a message along the socket. Get a message -> Don't poll or send notification, just send a message along the socket. Literally anything -> Don't make a request, just send a message along the socket.
Right now I'm leaning towards loading initial state and bulk data via normal HTTP URLs (eg: Create a thread, load the last 20 messages for thread XYZ), but for data that needs to be pushed and received in real time (eg: Chat Message send/recv) do that via a websocket.

Nats.io QueueSubscribe behavior on timeout

I'm evaluating NATS for migrating an existing msg based software
I did not find documentation about msg timeout exception and overload.
For Example:
After Subscriber has been chosen , Is it aware of timeout settings posted by Publisher ? Is it possible to notify an additional time extension ?
If the elected subscriber is aware that some DBMS connection is missing and cannot complete It could be possible to bounce the message
NATS server will pickup another subscriber and will re-post the same message ?
Ciao
Diego
For your first question: It seems to me that you are trying to publish a request message with a timeout (using the nc.Request). If so, the timeout is managed by the client. Effectively the client publishes the request message and creates a subscription on the reply subject. If the subscription doesn't get any messages within the timeout it will notify you of the timeout condition and unsubscribe from the reply subject.
On your second question - are you using a queue group? A queue group in NATS is a subscription that specifies a queue group name. All subscriptions having the same queue group name are treated specially by the server. The server will select one of the queue group subscriptions to send the message to rotating between them as messages arrive. However the responsibility of the server is simply to deliver the message.
To do what you describe, implement your functionality using request/reply using a timeout and a max number of messages equal to 1. If no responses are received after the timeout your client can then resend the request message after some delay or perform some other type of recovery logic. The reply message should be your 'protocol' to know that the message was handled properly. Note that this gets into the design of your messaging architecture. For example, it is possible for the timeout to trigger after the request recipient received the message and handled it but before the client or server was able to publish the response. In that case the request sender wouldn't be able to tell the difference and would eventually republish. This hints that such type of interactions need to make the requests idempotent to prevent duplicate side effects.

WebSocket client disconnect due to network loss doesn't get intercepted by Spring server

I have an application in which clients use websockets to connect to a server which is running Spring Boot Tomcat.
My question is if there is a way for the server to detect a client disconnect due to a network loss.
Thanks.
if you are using stomp , check SessionDisconnectEvent.
For raw Websocket connections, you can use :
WebSocketHandler-->afterConnectionClosed
I have searched before for this and the solution I was able to find was to implement a ping-pong mechanism between the server and the clients.
For example, each few seconds send a dummy message to the client on a specific topic and receive back another dummy reply, if you didn't get a reply for a configured period you can consider the client disconnected.
As mentioned here,
STOMP and Spring also allow us to set up topics, where every
subscriber will receive the same message. This is going to be very
useful for tracking active users. In the UI, each user subscribes to a
topic that reports back which users are active, and in our example
that topic will produce a message every 2 seconds. The client will
reply to every message containing a list of users with its own
heartbeat, which then updates the message being sent to other clients.
If a client hasn't checked in for more than 5 seconds (i.e. missed two
heartbeats), we consider them offline. This gives us near real time
resolution of users being available to chat. Users will appear in a
box on the left hand side of the screen, clicking on a name will pull
up a chat window for them, and names with an envelope next to them
have new messages.

Sending email in a queue such as MSMQ

I have asp.net MVC 3 application that sending various emails such as client registration, activation etc
Currently using smtpclient and smtp server authsmtp.com. In last 3 months there was number times application used to hang when sending email and smtp is not responding.
I am now required to review the process and improve with following improvement.
1.) Application should not hang when smtp server is not responding.
2.) Queue email for later delivery if smtp server is not available. Re-try delivery for next 24 hours
3.) Add extra logging for email queued, sent or failed (After 24 hrs)
I would like to know what will best option to implement the above requirement.
The application is hosted in windows azure environment.
I thought to use MSMQ as provides message queueing and I can log the details once each task is started and completed.
Reference : http://dotnetslackers.com/articles/aspnet/Sending-email-from-ASP-NET-MVC-through-MVC-and-MSMQ-Part1.aspx
The problem is that MSMQ is not supported on windows azure.
Please advise ?
Thanks
There is an example on WindowsAzure.com that covers a similar topic as this http://www.windowsazure.com/en-us/develop/net/tutorials/multi-tier-web-site/1-overview/

Resources