Laravel queue (iron.io) keeps sending same email over and over - php

I am using the Iron.io API with Laravel 5.1. It sends out emails fine. However, it seems to be sending the same message over and over again (4 times or more). Any idea why this might happen?
The code I am using is:
Mail::queue([], [], function ($message) use ($template, $order, $filename) {
$message
->to($order->email)
->subject($template->subject)
->setBody(DbView::make($template)->with($order->toArray())->render(), 'text/html');
$message->attach(storage_path('exports/'.$filename));
});

Ben hit the nail on the head.
In case it's handy, here's a link to the Iron.io developer docs:
This call gets/reserves messages from the queue. The messages will not be deleted, but will be reserved until the timeout expires. If the timeout expires before the messages are deleted, the messages will be placed back onto the queue. As a result, be sure to delete the messages after you're done with them.
http://dev.iron.io/mq/reference/api/#get_messages_from_a_queue

Related

Is there a way to delay a Mail by seconds or minutes when sending in laravel 5.8?

I have tried using later and queue then specified the seconds like below but i get an error saying "Only mailables may be queued"
Mail::later(5, $email)->send(new PasswordMail($data));
and
Mail::later(5, $email)->queue(new PasswordMail($data));
Here is my code when sending the email
Mail::to($email)->send(new PasswordMail($data));
The docs clearly describe how to delay mail sending:
Delayed Message Queueing
If you wish to delay the delivery of a queued email message, you may use the later method. As its first argument, the later method accepts a DateTime instance indicating when the message should be sent:
$when = now()->addMinutes(10);
Mail::to($request->user())
->cc($moreUsers)
->bcc($evenMoreUsers)
->later($when, new OrderShipped($order));
So in your case:
Mail::to($email)->later(now()->addMinutes(5), new PasswordMail($data));

Can't received inbound sms in plivo, it dosen't trigger codeigniter url

Recently I'm trying to received sms to plivo number. when i sent a sms from outsite plivo then it sent and plivo log status will show delivered. But i need to save data into database. It does not trigger to my controller function.
I already sent sms through another function. it sent and saved into my database but problem is, when anyone reply into this number.
controller function:
public function index()
{
// Sender's phone numer
$from_number = $this->input->get("From"); // $this->input->post("From"); dosen't work.
// Receiver's phone number - Plivo number
$to_number = $this->input->get("To"); // $this->input->post("To"); dosen't work.
// The SMS text message which was received
$text = $this->input->get("Text"); // $this->input->post("Text"); dosen't work.
// Output the text which was received to the log file.
// error_log("Message received - From: ".$from_number.", To: ".$to_number. ", Text: ".$text);
$arr = array("from" => $from_number, "to" => $to_number, "text" => $text);
$this->receive_model->add($arr);
}
Plivo application URL :
http://xxxxxxx.com/receive_sms
Message Method : GET
Message Method : POST // Dosen't work.
Codeigniter Config:
$config['allow_get_array'] = TRUE;
In plivo log status delivered.
any help?
Plivo started their Stop DND protocol a few days ago (i.e. June 2016). When a message comes back in response to a text from a Plivo phone number that says Stop... all further messages from Plivo are blocked.
The Plivo number sends a message and the recipient responds with Stop.
There is no do over. From then on, NO messages from Plivo will be delivered to that recipient as the recipients Stop message is interpreted as a request that all further messages be blocked.
Plivo offers no way of turning message delivery back on. That user has no way of correcting the Stop if sent in error. There is no do over.
All solutions lead to using a new different phone number.
A band aid... Incoming messages to that Plivo number still get received so there is the possibility of sending outgoing response messages from a second Plivo or other number. In theory looks OK BUT in reality this is at best a short term fix.
Most users naturally depend on sending messages by replying. Replying to the wrong new incoming number, instead of sending to the original phone number, just sets up another set of problems and issues to deal with. Not the least of those is what ever reason that caused the stop message in the 1st place or accidentally doing it again. Ends up like cutting your finger off 1/16th of an inch at a time.
At the first time i load plivo library class on the sms received controller, it was a problem. I just erase those line from controller and then it works fine.
We have to follow:
Plivo application always get data for codeigniter function. Codeigniter Config: $config['allow_get_array'] = TRUE; SMS received controller only load Codeigniter library file, nothing else.
It works for me.

ActiveMQ not returning message when queue has n number of pending messages

Environment/Background:
Using PHP Stomp library to send and receive message from ActiveMQ (v5.4.3).
Steps:
Client sends a message with reply-to & correlation-id headers to request queue (say /queue/request)
Subscribe to the response queue (say /queue/response)
Read frame
ack
unsubscribe
The above steps works fine when there is no pending message or pending message < n. In my case, n =200. When the number of pending message is > 200, the message is not delivered. The process waits till timeout and finally timeout without response. I can see the message (using admin UI) after timeout. Here is the code that I'm using for this case:
<?php
// make a connection
$con = new Stomp("tcp://localhost:61616");
// Set read timeout.
$con->setReadTimeout(10);
// Prepare request variables.
$correlation_id = rand();
$request_queue = '/queue/com.domain.service.request';
$response_queue = '/queue/com.domain.service.response';
$selector = "JMSCorrelationID='$correlation_id'";
$headers = array('correlation-id' => $correlation_id, 'reply-to' => $response_queue);
$message = '<RequestBody></RequestBody>';
// send a message to the queue.
$con->send($request_queue, $message, $headers);
// subscribe to the queue
$con->subscribe($response_queue, array('selector' => $selector, 'ack' => 'auto'));
// receive a message from the queue
$msg = $con->readFrame();
// do what you want with the message
if ( $msg != null) {
echo "Received message with body\n";
var_dump($msg);
// mark the message as received in the queue
$con->ack($msg);
} else {
echo "Failed to receive a message\n";
}
unset($con);
Other findings:
Sending messages from one file (say from sender.php) and receive using another script (say receiver.php) working fine.
Allows to send more than 1000 message in the same request queue(and eventually processed and placed in response queue). So it doesn't look like memory issue.
Funny enough, while waiting for timeout, if I browse the queue on admin UI, I get the response.
By default, the stomp broker that I use set the prefetch size to 1.
Without knowing more my guess is that you have multiple consumers and one is hogging the messages in it's prefetch buffer, the default size is 1000 I think. To debug situations like this it's usually a good idea to look at the web console or connect with jconsole and inspect the Queue MBean to see the stats for in-flight messages, number of consumers etc.
Answering my own question.
The problem I'm facing is exactly what is described in http://trenaman.blogspot.co.uk/2009/01/message-selectors-and-activemq.html and the solution is to increase the maxPageSize as specified in ActiveMQ and maxPageSize
As you can match that the 200 is not a varying number, but the default value of maxPageSize.
More references:
http://activemq.2283324.n4.nabble.com/Consumer-is-not-able-to-pick-messages-from-queue-td2531722.html
https://issues.apache.org/jira/browse/AMQ-2217
https://issues.apache.org/jira/browse/AMQ-2745

Sending emails with mailgun and Laravel

I am trying to learn how to send emails using Mailgun in Laravel. When I try to send the email I get a timeout that says: Maximum execution time of 60 seconds exceeded
The application times out here:
$line = fgets($this->_out);
I have a route that activates when I click a button on my email page:
Route::post('/email', 'MainController#sendEmail');
Here is my controller function (replaced my email for privacy reasons):
public function sendEmail() {
$data = [
'title'=>'Email'
];
Mail::send('emails.hello', $data, function($message) {
$message->from('example#gmail.com', 'Example Person');
$message->to('example#gmail.com')->subject('we made it');
});
return Redirect::to('/');
}
Any ideas on what I may do be doing wrong?
This generally happens if the SMTP port used in the app/config/mail.php config file is not opened by your hosting provider. Please check and ask them to open the port. This should resolve the issue.
Sending emails through mailgun could not be simpler, just add the API package, publish and update the config and use the custom facade to send them (changing Mail::send() to Mailgun::send())
You can find the package here: http://packalyst.com/packages/package/vtalbot/mailgun
I know this doesn't really address the error your getting (would need more information to help with that), but using the package does simplify the whole thing!

Keep messages from ACKing on get() using pecl-amqp

I'm attempting to use pecl-amqp for a project of mine. I'm having difficulties though with the ACK process. I need to manually ACK each message I receive off a queue, but the messages appear to be auto-ACKing when the message is retrieved.
I've set my queue to AMQP_NOACK and am using AMQPQueue->get(AMQP_NOACK) but none of it seems to have any affect, the messages are still removed from the queue without me sending AMQPQueue->ack().
If anyone has any experience with the pecl-amqp I would appreciate the help.
I have been having the same problem but have managed to get the acknowledge mechanism to work using the consume method. Using rabbitmqctl to list the entries in the queue it appears to work OK, though I seems to be getting the messages off the queue in a different order to that in which they were sent - which kind of defeats the object of a queue. My code is as follows:
// Create the queue to be:
// AMQP_DURABLE - messages will withstand a broker restart (i.e. they are written to disk).
// AMQP_NOACK - when consumed messages will not be marked as delivered until an explicit ACK is received.
$q->declare($queueName, AMQP_DURABLE | AMQP_NOACK );
// Bind it on the exchange to routing key.
$q->bind($exchangeName, $routingKey);
// Set the options for our consumption of the messages:
// Get a minimum of 0 msg.
// Get a maximum of 1 msg.
// Don't ACK the message on consumption i.e. explicitly acknoledge later.
$options = array(
'min' => 0,
'max' => 1,
'ack' => false
);
// Get the messages
$results_array = $q->consume($options);
// show the message
print_r($results_array);
$delivery_tag = $results_array[0]['delivery_tag'];
echo 'delivery_tag: [' . $delivery_tag . "].\r\n";
// Acknowledge receipt of the message.
$q->ack($delivery_tag);
For reference, the AMQP extension did not support the AMQP_NOACK correctly. You can get it to do what you want, but it isnt pretty. I am working on fixing that now. FYI, AMQP_NOACK means that you will not have to come back to acknowledge the message later, i.e. as soon as the server sends the message to the client, the server marks the message as ack'ed. There has been some confusion around this, so I wanted to clarify.

Categories