18
JBoss AS7/EAP6 - JMS and JMX - 최지웅(놀새~) 컨설팅 코치 주식회사 오픈 소스 컨설팅

JBoss AS7/EAP6 - JMS and JMX

Embed Size (px)

DESCRIPTION

This is a guide document that how you can setting up JMS Queue and JMX on JBoss AS 7.1.1.Final or EAP6. In EAP5, server port for JMS used 1099, but EAP6 doesn't use that port any longer. This also explains about JBoss JMX to monitor Java heap and JMX via MBean. If you want to get more information or open source, please email

Citation preview

Page 1: JBoss AS7/EAP6 - JMS and JMX

JBoss AS7/EAP6

- JMS and JMX -

최지웅(놀새~) –컨설팅 코치

주식회사 오픈 소스 컨설팅

Page 2: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

Potential Receiver 2

Potential Receiver 1 메시지 1

메시지 2

- Point-to-Point 모델에서는 Sender에 의해 발생된 메시지가 Queue라는 채널에 전달되고, 이 메시지는 Queue에 의해 자동으로 Receiver에 전달

- Publisher/Subscriber 모델과 다른 점은 Queue에 전달된 하나의 메시지는 오직 하나의 Receiver에만 전달되고 다수의 Receiver 에 전달되지 않음

- Sender에 의해 Queue에 전달된 메시지1은 Queue에 의해 Receiver1에 전달되고, Sender에 의해 전달된 메시지2는 Queue에 의해 Receiver2에 전달

- Publisher/Subscriber 모델처럼 동일한 메시지가 서로 다른 Receiver에 전달되지 않음

Sender

Queue

메시지2

메시지1

JMS Queue

Page 3: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

- Publisher/Subscriber 모델에서는 Publisher가 하나의 메시지를 다수의 Subscriber(Consumer)에게 Topic 이라는 채널을 통하여 전달

- 모든 Subscriber는 Publisher가 Topic에 보낸 하나의 메시지의 사본을 전달 받게 되며, 이와 같은 메시지 전달은 Topic에 의해 자동으로 Subscriber에 전달

- Publisher 에 의해 전달된 메시지1은 동시에 Subscriber1, Subscriber2 에 전달되며, Publisher에 의해 전달된 2번째 메시지인 메시지2 도 Subscriber1, Subscriber2에 전달

Publisher

Topic

Subscriber

Subscriber

메시지2

메시지1

메시지 1 메시지 2

메시지 1 메시지 2

JMS Topic

Page 4: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

?

Sender Receiver Connection

Session

Producer

Consumer

JBoss Netty

Core

Client-side Delegates

Client-side aspects

Server-side aspects

Server-side endpoints

JBoss JMS 핵심 기능

JMS 1.1 스펙 준수 및 JBoss AS의 런타임 라이브러리로 사용.

성능, 신뢰성, 안정성 및 낮은 응답시간 등에 초점을 둠.

SOA의 초기 단계인 JBoss ESB의 핵심 모듈로서 사용

Netty 기반의 고성능 자바 엔진(LDAP, DNS, Keberos, etc)

Page 5: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

JBoss Netty – 고성능 네트워크 클라이언트/서버 프레임워크

이벤트 기반 비동기 네트워크 애플리케이션 프레임워크

Interceptor Chain 패턴

• 손쉽게 다단계 State machine 구현

• 암복호화 + 전문 해석 + 스레드 풀링 + 비즈니스 로직

• 조립 가능한 컴포넌트 다수 제공

과부하 및 DoS 방어 메커니즘

Old · New I/O 모두 지원

NIO 구현·벤더별 최적화

Page 7: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

JMS Queue 생성

Naming이 java:jboss/exported/ 로 시작되지 않으면 글로벌 JNDI에 바인딩되지 않음

Page 8: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

JMS 사용자 생성

C:\Java\jboss-eap-6.1\bin>add-user.bat

JAVA_HOME is not set. Unexpected results may occur.

Set JAVA_HOME to the directory of your local JDK to avoid this message.

What type of user do you wish to add?

a) Management User (mgmt-users.properties)

b) Application User (application-users.properties)

(a): b

Enter the details of the new user to add.

Realm (ApplicationRealm) :

Username (testuser) : ienvyou

Password : !test123

Re-enter Password : !test123

What roles do you want this user to belong to? (Please enter a comma separated list, or leave blank for

none)[ ]: testrole

About to add user 'ienvyou' for realm 'ApplicationRealm'

Is this correct yes/no? yes

Added user 'ienvyou' to file 'C:\Java\jboss-eap-6.1\standalone\configuration\application-users.properties'

Added user 'ienvyou' to file 'C:\Java\jboss-eap-6.1\domain\configuration\application-users.properties'

Added user 'ienvyou' with roles testrole to file 'C:\Java\jboss-eap-

6.1\standalone\configuration\application-roles.properties'

Added user 'ienvyou' with roles testrole to file 'C:\Java\jboss-eap-6.1\domain\configuration\application-

roles.properties'

Is this new user going to be used for one AS process to connect to another AS process?

e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server

EJB calls.

yes/no?

JMS 접근 사용자 생성

Page 9: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

송수신 권한 설정

<security-settings>

<security-setting match="#">

<permission type="send" roles="guest"/>

<permission type="consume" roles="guest"/>

<permission type="createNonDurableQueue" roles="guest"/>

<permission type="deleteNonDurableQueue" roles="guest"/>

</security-setting>

</security-settings>

<security-settings>

<security-setting match="#">

<permission type="send" roles="guest testrole"/>

<permission type="consume" roles="guest testrole"/>

<permission type="createNonDurableQueue" roles="guest"/>

<permission type="deleteNonDurableQueue" roles="guest"/>

</security-setting>

</security-settings>

standalone-full.xml<before>

standalone-full.xml<after>

Page 10: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

애플리케이션을 통한 테스트

try {

Hashtable<String, String> properties = new Hashtable<String, String>();

properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

properties.put(Context.PROVIDER_URL, "remote://localhost:4447");

properties.put(Context.SECURITY_PRINCIPAL, "admin");

properties.put(Context.SECURITY_CREDENTIALS, "!test123");

Context ctx = new InitialContext(properties);

ConnectionFactory cf = (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory"); Queue queue = (Queue) ic.lookup(destinationName);

System.out.println("Queue " + destinationName + " exists");

Connection connection = cf.createConnection("ienvyou", "!test123"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

MessageProducer sender = session.createProducer(queue);

sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

TextMessage message = session.createTextMessage("Hello!");

sender.send(message);

System.out.println("The message was successfully sent to the " + queue.getQueueName() + " queue");

connection.start();

} catch(Exception e) {

}

closeConnection(connection);

Page 11: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

Firewall hardware

Server

Web server software

Server Application

DB server software

Management console

Management console

Management console

Management console

Management console

Before JMX

Before JMX

벤더 고유의 관리 콘솔을 제공

일반적으로 웹 브라우저를 통하여 접근하도록 설계

API를 제공해주지 않을 경우 해당 관리 객체에 접근하기 어려움

Page 12: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

With JMX(Java Management Extension)

Firewall hardware

Server

Web server software

Server Application

DB server software Management console

JMX Agent

Adapter

= JMX MBean

http://www.jcp.org/en/jsr/detail?id=255 JSR 255: JavaTM Management Extensions (JMXTM) Specification, version 2.0

JMX를 이용할 경우 소프트웨어 관리 포인트를 한 곳으로 집중할 수 있다는 장점이 발생.(JSR-255)

• 모든 리소스는 MBean을 사용하여 관리.

• JMX Agent (or group of agents)상의 모든 MBean은 하나의 관리 콘솔에서 모두 처리

Page 13: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

WebLogic JMX 적용 예

------------------------------------------------------------------------------------------------------------------

com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean

ServerRuntimes

------------------------------------------------------------------------------------------------------------------

Server Name

Server State

Server JVMRuntime Name

Server JVMRuntime HeapSizeCurrent

Server JVMRuntime HeapFreeCurrent

Server JMSRuntime JMSServers Name

Server JMSRuntime JMSServers Destinations Name

Server JMSRuntime JMSServers Destinations ConsumersCurrentCount

Server JMSRuntime JMSServers Destinations ConsumersHighCount

Server JMSRuntime JMSServers Destinations ConsumersTotalCount

Server JMSRuntime JMSServers Destinations MessagesCurrentCount

Server JMSRuntime JMSServers Destinations MessagesHighCount

Server JMSRuntime JMSServers Destinations MessagesPendingCount

Server JMSRuntime JMSServers Destinations MessagesReceivedCount ------------------------------------------------------------------------------------------------------------------

com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean

DomainConfiguration

------------------------------------------------------------------------------------------------------------------

Domain JMSSystemResources JMSResource Name

Domain JMSSystemResources JMSResource Queues Name

Domain JMSSystemResources JMSResource Queues JNDIName

Domain JMSSystemResources JMSResource DistributedQueues Name

Domain JMSSystemResources JMSResource DistributedQueues JNDIName

Domain JMSSystemResources JMSResource DistributedQueues DistributedQueueMembers Name

DomainRuntimeMBean을 통한 현재 JVM 및 JMS 상태 정보

JMS 관련 Queue 설정 정보 확인

Page 14: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

JMX Object Name 수집

C:\Java\jboss-eap-6.1\bin> standalone.bat -c standalone-full

C:\Java\jboss-eap-6.1\bin> jconsole.bat

Page 15: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

JVM Heap ObjectName

Page 16: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

JMS ObjectName

Page 17: JBoss AS7/EAP6 - JMS and JMX

- Internal Use Only -

JMX Code Example

import java.util.HashMap;

import javax.management.MBeanServerConnection;

import javax.management.openmbean.CompositeDataSupport;

import javax.management.openmbean.CompositeType;

import javax.management.remote.JMXConnector;

import javax.management.remote.JMXConnectorFactory;

import javax.management.remote.JMXServiceURL;

import javax.management.*;

public class HeapAccess {

public static void main(String[] args) throws Exception {

String host = "127.0.0.1"; // Your JBoss Bind Address default is localhost

int port = 9999; // JBoss remoting port

String urlString ="service:jmx:remoting-jmx://" + host + ":" + port;

System.out.println(" \n\n\t**** urlString: "+urlString);

HashMap environment = new HashMap();

String[] credentials = new String[] {"test", "!test123"};

environment.put (JMXConnector.CREDENTIALS, credentials);

JMXServiceURL serviceURL = new JMXServiceURL(urlString);

JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, environment);

MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

ObjectName objectName=new ObjectName("java.lang:type=Memory");

CompositeDataSupport heapMemoryUsage =(CompositeDataSupport)connection.getAttribute(objectName, "HeapMemoryUsage");

System.out.println(" committed = " + heapMemoryUsage.get("committed"));

System.out.println(" init = " + heapMemoryUsage.get("init"));

System.out.println(" max = " + heapMemoryUsage.get("max"));

System.out.println(" used = " + heapMemoryUsage.get("used"));

jmxConnector.close();

}

}

Page 18: JBoss AS7/EAP6 - JMS and JMX

18 - Internal Use Only -

요약

OPEN

SHARE

CONTRIBUTE

ADOPT

REUSE