Este conteúdo não está disponível no idioma selecionado.

19.6. HelloWorld Example: Rule "Hello World"


rule "Hello World"
      dialect "mvel"
  when
      m : Message( status == Message.HELLO, message : message )
  then
      System.out.println( message ); 
      modify ( m ) { message = "Goodbye cruel world",
                     status = Message.GOODBYE };
end
Copy to Clipboard Toggle word wrap
  • The LHS (after when) section of the rule states that it will be activated for each Message object inserted into the Working Memory whose status is Message.HELLO.
  • Two variable bindings are created: the variable message is bound to the message attribute and the variable m is bound to the matched Message object itself.
  • The RHS (after then) or consequence part of the rule is written using the MVEL expression language, as declared by the rule's attribute dialect.
  • After printing the content of the bound variable message to System.out, the rule changes the values of the message and status attributes of the Message object bound to m.
  • MVEL's modify statement allows you to apply a block of assignments in one statement, with the engine being automatically notified of the changes at the end of the block.
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat