Árvore de páginas

Obtém uma mensagem da Fila

Sintaxe

 

nRet := oTQLS:WaitMsg( @cMsgId, @cMsg, [@nMsgLen], [nTimeOut])

Parâmetros

NomeTipoDescriçãoObrigatórioReferênciaObservações
cMsgId
Caractereé preenchido com o identificador da mensagemXX 
cMsgCaractereé preenchido com a mensagem recuperadaXX 
nMsgLen
Numéricose informado é preenchido com o tamanho da mensagem recebida X 
nTimeOut
NuméricoTempo em segundos que fica aguardando para receber uma mensagem na fila  

se não houver mensagem para ser retirada, retorna erro com o valor da propriedade "eNO_MSGS"

Se for 0 (zero) verifica e retorna imediatamente, se não for informado fica aguardando indefinidamente até chegar uma mensagem na fila

Retorno

NomeTipoDescriçãoObservações
nRet 
Numérico

se executou corretamente retorna 0 ("OK"), caso contrário contem o número do erro

 

Observações

Uma mensagem só é removida da fila após ser explicitamente chamada a função "TQueueSvc:DelMsg"

Exemplos

Exemplo 

WaitMsg
#include 'protheus.ch'

// Setup Redis
Static cRedisHost := "tec-clima"
Static nRedisPort := 6379


User Function FilGet()
  Local nRet       := 0
  // ID da mensagem
  Local cMsgId1    := ""
  // Mensagem a receber
  Local cMsg       := ""
  // Nome da Fila
  Local cQueueName := "Fila_TQLS"
  // Objeto de Fila
  Local oTQLS := Nil
  Local nNO_MSGS := 0
  // Cria um novo objeto de Fila
  oTQLS := TQueueSvc():New(cQueueName)
  If(oTQLS == Nil)
    ConOut("### ERRO ### " + "Erro na criacao da Fila - " + cQueueName)
    Return .F.
  Else
    ConOut("Criacao da Fila  OK - " + oTQLS:cName)
  EndIf
  // Configurando a Fila
  nRet := oTQLS:Setup(cRedisHost, nRedisPort)
  If nRet != 0
    ConOut("### ERRO ### " + "Erro ao fazer o Setup" + " Erro: " + AllTrim(Str(nRet)))
    Return .F.
  Else
    ConOut("Setup de Fila    OK - " + oTQLS:cName + " nMsgRetPer: " + AllTrim(Str(oTQLS:nMsgRetPer)) + " nVisTimeOut: " + AllTrim(Str(oTQLS:nVisTimeOut)))
  EndIf
  // Obtendo valor de indicacao de que nao tem mais mensagens
  nNO_MSGS := oTQLS:eNO_MSGS
  // Obtem a mensagem
  nRet := oTQLS:WaitMsg( @cMsgId1, @cMsg, , 3 )
  If nRet != 0
    If(nRet == nNO_MSGS)
      ConOut("OK, nao existem mensagens na Fila. (Execute U_FilPut)")
    Else
      ConOut("### ERRO ### " + "Erro ao receber mensagem" + " Erro: " + AllTrim(Str(nRet)))
      Return .F.
    EndIf
  Else
    ConOut("Recebeu msg Fila OK - " + oTQLS:cName + " com ID: " + cMsgId1 + " Tamanho: " + AllTrim(Str(Len(cMsg))))
  EndIf
Return .T.

Veja também

  • Sem rótulos