• Link to Facebook
  • Link to LinkedIn
  • Link to X
  • Link to Youtube
  • 로그인
  • 회원가입
  •  한글 한글 한글 ko
  • English English 영어 en
OPENMARU APM
  • 오픈마루
    • 회사소개
    • 연혁
    • 오픈마루 CI
  • 제품
    • OPENMARU Cloud APM
      • Application 모니터링
      • Openshift & Kubernetes 모니터링
      • WEB/WAS 모니터링
      • URL 모니터링
      • Cubrid 모니터링
    • OPENMARU Cluster
    • OPENMARU Dashboard
  • 오픈소스
    • 쿠버네티스
    • 아파치 톰캣
    • CentOS
  • 레드햇
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat JBoss EAP
  • 가격 안내
  • 조달물품
    • G2B 딜 등록
    • 조달물품 OPENMARU APM
    • 조달물품 OPENMARU Cluster
    • 혁신장터
  • 레퍼런스
  • 고객지원
  • 문서
  • 블로그
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu

룰 엔진으로 선언적 프로그래밍 – Drools 6.0

Drools 6.0을 통한 룰 엔진으로 선언적 프로그래밍의 기초를 배워보세요.

JBoss Tips & Tricks - Red Hat JBoss Enterprise Application Platform

초보자를 위한 룰엔진 프로그램밍


Drools 6.0 룰 엔진에서 선언적 프로그래밍 형태의 간단한 룰 애플리케이션을 작성해 봅니다.

선언적 프로그래밍은 ‘어떻게 해야 하는가’(How to do it) 아닌 무엇을 해야 하는가 ’What to do’에 집중하여 프로그래밍하는 방법입니다.

예를 들자면 “최댓값 구하기”를 절차적 프로그래밍 언어로 구현한다면 루프를 이용하여 값의 집합에서 각 값을 반복적으로 비교하고 최종적으로 최댓값을 구하는 코드로 작성할 것입니다.

만약 이 문제를 룰 시스템을 이용하여 해결한다면 최댓값은 값의 집합 중에 가장 큰 값이 될 것입니다. 즉 “값의 집합에서 그 값보다 큰 값이 존재하지 않는 값” 이라고 할 수 있습니다.

아래의 룰에 선언되어 있는 것처럼 HR 이라는 부서에 height 가 maxheight 보다 큰 값이 존재 하지 않는 것입니다.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<span style="font-size: 14pt;">when
memMaxHeight: Member( section == "HR", maxheight : height )
not Member( section == "HR", height > maxheight)</span>
<span style="font-size: 14pt;">when memMaxHeight: Member( section == "HR", maxheight : height ) not Member( section == "HR", height > maxheight)</span>
when
    memMaxHeight: Member( section == "HR", maxheight : height )
    not Member( section == "HR", height > maxheight)

선언적 프로그래밍은 최댓값이 필요한 경우 위와 같이 최댓값의 정의 그대로 프로그램에 적용하는 것입니다.

초보자를 위한 룰엔진 프로그래밍

1. 샘플 애플리케이션 작성


이제부터 HR 부서에서 가장 키가 큰 사람을 찾아내는 프로그램을 룰 엔진을 이용해 작성합니다.

앞으로 작성하는 프로젝트는 다음과 같은 형태이니 참조합니다.

샘플 애플리케이션 프로젝트 형태

2. pom.xml을 다음과 같이 작성하여 프로젝트 Dependency를 정의


Drools 6.0.0.Final 을 기반으로 Eclipse 프로젝트를 생성합니다. 로깅을 위하여 org.slf4j 도 dependency 에 함께 포함합니다.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelversion>4.0.0</modelversion>
<groupid>drools.sample3</groupid>
<artifactid>drools.sample3</artifactid>
<version>0.0.1-SNAPSHOT</version>
<properties>
<droolsversion>6.0.0.Final</droolsversion>
</properties>
<dependencies>
<dependency>
<groupid>org.drools</groupid>
<artifactid>drools-compiler</artifactid>
<version>${droolsVersion}</version>
</dependency>
<dependency>
<groupid>org.slf4j</groupid>
<artifactid>slf4j-simple</artifactid>
<version>1.7.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>drools.sample3</groupid> <artifactid>drools.sample3</artifactid> <version>0.0.1-SNAPSHOT</version> <properties> <droolsversion>6.0.0.Final</droolsversion> </properties> <dependencies> <dependency> <groupid>org.drools</groupid> <artifactid>drools-compiler</artifactid> <version>${droolsVersion}</version> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-simple</artifactid> <version>1.7.2</version> <scope>runtime</scope> </dependency> </dependencies> </project>

     4.0.0
     drools.sample3
     drools.sample3
     0.0.1-SNAPSHOT
     
          6.0.0.Final
     
     
          
               org.drools
               drools-compiler
               ${droolsVersion}
          
 
          
               org.slf4j
               slf4j-simple
               1.7.2
               runtime
          
     

3. 회사의 개별 직원을 나타내는 Member 클래스를 정의


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.sample;
public class Member {
private String name;
private String section;
private int height;
public Member(String name, String section, int height) {
super();
this.name = name;
this.section = section;
this.height = height;
}
public String getSection() {
return section;
}
public void setSection(String name) {
this.section = name;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.sample; public class Member { private String name; private String section; private int height; public Member(String name, String section, int height) { super(); this.name = name; this.section = section; this.height = height; } public String getSection() { return section; } public void setSection(String name) { this.section = name; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
package com.sample;
 
public class Member {
     private String name;
     private String section;
     private int height;
 
     public Member(String name, String section, int height) {
          super();
          this.name = name;
          this.section = section;
          this.height = height;
     }
 
     public String getSection() {
          return section;
     }
 
     public void setSection(String name) {
          this.section = name;
     }
 
     public int getHeight() {
          return height;
     }
 
     public void setHeight(int height) {
          this.height = height;
     }
 
     public String getName() {
          return name;
     }
 
     public void setName(String name) {
          this.name = name;
     }
 
}

4. 마지막으로는 앞서도 간단히 언급한 룰에 대한 정의 파일


sample.drl 의 파일 내용은 다음과 같습니다.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.sample
import com.sample.Member;
rule "maxHeight"
when
memMaxHeight: Member( section == "HR", maxheight : height )
not Member( section == "HR", height > maxheight)
then
System.out.println("가장 키가 큰 사람의 키는?、"+maxheight+"cm 입니다.");
System.out.println("가장 키가 큰 사람은 "
+memMaxHeight.getName()
+"이며, 키는 "
+memMaxHeight.getHeight()
+"cm 입니다.");
end
package com.sample import com.sample.Member; rule "maxHeight" when memMaxHeight: Member( section == "HR", maxheight : height ) not Member( section == "HR", height > maxheight) then System.out.println("가장 키가 큰 사람의 키는?、"+maxheight+"cm 입니다."); System.out.println("가장 키가 큰 사람은 " +memMaxHeight.getName() +"이며, 키는 " +memMaxHeight.getHeight() +"cm 입니다."); end
package com.sample
 
import com.sample.Member;
 
rule "maxHeight"
  when
    memMaxHeight: Member( section == "HR", maxheight : height )
    not Member( section == "HR", height > maxheight)
  then
    System.out.println("가장 키가 큰 사람의 키는?、"+maxheight+"cm 입니다.");
    System.out.println("가장 키가 큰 사람은 "
         +memMaxHeight.getName()
         +"이며, 키는  "
         +memMaxHeight.getHeight()
         +"cm 입니다.");
end

when 절에서 “maxheight 보다 큰 값을 가진 멤버는 없다는 룰” 이 적용된 결과 입니다.

when 절의 첫 번째 룰은 ‘section ==”HR” 전체 멤버이며, 두 번째 룰은 HR 멤버 중 자신의 키보다 큰 키를 가지는 멤버는 존재하지 않는 다는 것입니다.

5. Java Application 실행 결과는 다음과 같습니다.


앞에서 작성한 룰 애플리케이션은 Java Application 으로 실행하며 결과는 다음과 같이 출력됩니다.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
가장 키가 큰 사람의 키는?、172cm 입니다.
가장 키가 큰 사람은 사용자2이며, 키는 172cm 입니다.
가장 키가 큰 사람의 키는?、172cm 입니다. 가장 키가 큰 사람은 사용자2이며, 키는 172cm 입니다.
가장 키가 큰 사람의 키는?、172cm 입니다.
가장 키가 큰 사람은 사용자2이며, 키는 172cm 입니다.

Drools 6.0 룰 엔진에서 선언적 프로그래밍 형태로 룰을 사용하는 간단한 샘플을 작성해 보았습니다.

References & Related Links


  • https://www.drools.org/learn/documentation.html

거침없이 배우는 JBoss – 10점
전준식 엮음/지&선(지앤선)

JBoss Tips & Tricks - Red Hat JBoss Enterprise Application Platform

룰 엔진으로 선언적 프로그래밍 – Drools 6.0

2014-03-11/in JBoss/by 오픈마루 마케팅3
Read more
https://i0.wp.com/www.openmaru.io/wp-content/uploads/2024/04/009_drools6_title.jpg?fit=380%2C302&ssl=1 302 380 오픈마루 마케팅3 https://www.openmaru.io/wp-content/uploads/2020/11/logo@2x.png 오픈마루 마케팅32014-03-11 11:42:132024-04-16 13:41:38룰 엔진으로 선언적 프로그래밍 – Drools 6.0
거침없이 배우는 JBoss - 오픈소스 미들웨어 JBoss EAP 6 & AS 7 이해하기

JBoss EAP 6 – 거침없이 배우는 JBoss

2014-02-28/in JBoss/by 오픈마루 마케팅3
Read more
https://i0.wp.com/www.openmaru.io/wp-content/uploads/2024/04/008_jboss_title.jpg?fit=380%2C302&ssl=1 302 380 오픈마루 마케팅3 https://www.openmaru.io/wp-content/uploads/2020/11/logo@2x.png 오픈마루 마케팅32014-02-28 10:59:002024-08-23 13:40:58JBoss EAP 6 – 거침없이 배우는 JBoss
Undertow vs JBoss 비교자료

JBoss EAP 7 웹컨테이너 Undertow – 핵심 이해와 활용 방법

2014-02-27/in JBoss, Tech Talk/by 오픈마루 마케팅3
Read more
https://i0.wp.com/www.openmaru.io/wp-content/uploads/2024/02/Undertow_vs_JBossWeb1.png?fit=900%2C500&ssl=1 500 900 오픈마루 마케팅3 https://www.openmaru.io/wp-content/uploads/2020/11/logo@2x.png 오픈마루 마케팅32014-02-27 09:53:582024-04-16 13:42:14JBoss EAP 7 웹컨테이너 Undertow – 핵심 이해와 활용 방법
Page 22 of 24«‹2021222324›»

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp

Like this:

Like Loading...

Recent Posts

  • JBoss EAP 8.1 베타 | 엔터프라이즈 Java 애플리케이션 현대화 2025-05-12
  • ChatGPT 프롬프트 엔지니어링, 이렇게 시작하세요! 2025-05-08
  • 올해 1분기, 사람들이 가장 많이 본 OPENMARU 콘텐츠는? 2025-04-17
  • 보안 강화의 다음 단게, mTLS를 아시나요? 2025-04-03
  • 성공적인 MSA 구축을 위한 핵심 전략 대공개! 테크 엣지 세미나 안내 2025-03-21

Categories

  • APM
  • Cloud
  • Cloud Native Seminar
  • Cluster
  • gift
  • JBoss
  • Kubernetes
    • Container
  • Linux
  • Microservices Architecture
  • News
  • Newsletter
  • OPENMARU
    • Dashboard
  • OpenShift
  • Red Hat
  • Seminar
    • gift
  • Tech Talk
  • 발표자료
  • 분류되지 않음
  • 오픈나루 공지사항
  • 오픈소스

이메일로 블로그 구독하기

이 블로그를 구독하고 이메일로 새글의 알림을 받으려면 이메일 주소를 입력하세요

Tags

APM cloud Cloud Native Container Docker Hybrid Cloud jboss JBoss EAP Kubernetes Kubernetes 모니터링 linux MSA Native OPENMARU OPENMARU APM OpenShift Openshift Promotion PaaS PaaS 플랫폼 Red Hat redhat RHEL tomcat Virtualization WAS Wildfly 가상화 네이티브 도커 레드햇 리눅스 모니터링 브리핑 세미나 오픈마루 오픈마루 APM 오픈시프트 주간 진짜 클라우드 컨테이너 쿠버네티스 클라우드 클라우드 네이티브 클라우드네이티브 클라우드 네이티브 세미나

Search

Search Search

오픈마루

04778 서울시 성동구 뚝섬로1길 31 906 호
(성수동1가, 서울숲M타워)

Tel : 02-469-5426 | Fax : 02-469-7247
Email : sales@openmaru.io

  • OPENMARU CLOUD APM
    • Application 모니터링
    • Openshift & Kubernetes 모니터링
    • WEB/WAS 모니터링
    • URL 모니터링
    • Cubrid 모니터링
  • 가격안내
  • 고객 레퍼런스
  • 고객지원
    • 문서
    • 사용자가이드
    • 기술지원
  • 블로그
  • 이용약관
  • 개인정보처리방침
  • 서비스수준협약
  • 회사소개
Copyright © OPENMARU, Inc. All Rights Reserved. - powered by Enfold WordPress Theme
  • Link to Facebook
  • Link to LinkedIn
  • Link to X
  • Link to Youtube
Link to: JBoss EAP 6 – 거침없이 배우는 JBoss Link to: JBoss EAP 6 – 거침없이 배우는 JBoss JBoss EAP 6 – 거침없이 배우는 JBoss거침없이 배우는 JBoss - 오픈소스 미들웨어 JBoss EAP 6 & AS 7 이해하기 Link to: JBoss Data Grid PostgreSQL Cache Store 사용하기 Link to: JBoss Data Grid PostgreSQL Cache Store 사용하기 JBoss Enterprise Data GridJBoss Data Grid PostgreSQL Cache Store 사용하기
Scroll to top Scroll to top Scroll to top
  • 한글
  • English
%d