I was thinking about this problem and I had an idea along the lines of TDZWeb. Instead of logging the user out and redirecting them to a content page or other generic page, maybe you can redirect the user to another page for further processing. For example, look at this code:
$app->logout();
$app->redirect(JRoute::_('index.php?option=mycomponent&view=mymessagequeue&myvar=1'));
After the application logs the user out and the page reloads, the message queue gets wiped out. So, how about instead set an extra variable in your redirect. Use this extra variable to determine the message you want to display to the end user. Then in your view.html.php file for the mymessagequeue view, add some code like this:
$myvar = JRequest::getInt('myvar');
switch($myvar){
case 1:
$mymessage = "MESSAGE 1";
break;
case 2:
$mymessage = "MESSAGE 2";
break;
case 3:
$mymessage = "MESSAGE 3";
break;
}
$app->redirect(JRoute::_('index.php?option=mycomponent&view=myview', $mymessage);
Here the user is redirected twice after logout. The first time the user is redirected the application's message queue and user session are cleared out. The second time the user is redirected, a message is set for the guest user and the message queue should retain it.