Este contenido no está disponible en el idioma seleccionado.

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.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat