Skip to main content

JEAP 6 - 建立DataSource 連結


今天早上在捷運上習慣性地拿出手機想要滑滑~
結果發現~我忘記帶了!!!!!!
天啊!整段捷運我都不知道要幹嘛~好漫長的一段路程!

無法想象沒有iPhone 的世界了,哈哈!
本來想先作Cluster 的,但是因為設定JDBC 被追殺的比較勤!
========================================================
環境: 因為我還沒裝Cluster, 所以目前一切以Standalone為主,
但是 Domain 跟 Standalone 的設定方式是一樣的!所以請自行帶入!!

DB:  當然是用Postgresql! 
OS: Linux 


安裝 Datasource 主要有兩個步驟,
A. 安裝JDBC Driver 
B. 設定JNDI 連結

安裝JDBC Driver

有許多種的選擇
1. Hot Deployment 
2. Module Drivers

1. Hot Deployment 的安裝方式最簡單,但也因為簡單,所以限制也比較大。
也是在開發的時候,最快速的做法,因為這種方式連設定都不用設定!
因為完全不用設定,它就會有一定的限制

❧ 因為需要Jar檔裡面META-INF 裡面metadata定義的Driver 名稱,而JDBC的Standard ㄧ直到4 才製定。(除了MySql 的 driver 之外應該都可以用,因為MySql 自稱沒有通過SQL 92 full compliance tests。)

不支援 XADataSourceClass

❧ 不支援多個jar檔的Driver,如,過你用Oracle 的時候,需要使用特殊語系用到orai18n.jar  這種plugin的雙jar檔就不行拉!


安裝方式,新版的JBoss 提供了許多介面讓使用者可以隨便自己喜歡的方式操作。

第一種,檔案直接傳輸
直接把jar檔 copy 進 $JBOSS_HOME/standalone/deployments 即可,這時,你會看到
下面的log, 就代表你已經安裝JDBC Driver 成功了!

[root@jboss1 tmp]# cp postgresql-9.1-902.jdbc4.jar /opt/jboss-eap-6.0/standalone/deployments/
[root@jboss1 tmp]# tail /opt/jboss-eap-6.0/standalone/log/server.log
09:05:48,897 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "postgresql-9.1-902.jdbc4.jar"
09:05:49,161 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) JBAS010404: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.1)
09:05:49,170 INFO  [org.jboss.as.osgi] (MSC service thread 1-1) JBAS011907: Register module: Module "deployment.postgresql-9.1-902.jdbc4.jar:main" from Service Module Loader
09:05:49,485 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "postgresql-9.1-902.jdbc4.jar"




第二種,使用CLI
小妹的淺見,這根本就是耍帥用的界面!都是command base的!
有的時候我去客戶那邊也會用這個,因為這樣比較帥..不對...是快!哈。

[root@jboss1 bin]# ./jboss-cli.sh 
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect 172.16.1.77:9999
[standalone@172.16.1.77:9999 /] deploy /tmp/postgresql-9.1-902.jdbc4.jar
[standalone@172.16.1.77:9999 /] exit
[root@jboss1 bin]# tail -f /opt/jboss-eap-6.0/standalone/log/server.log
10:00:07,452 INFO  [org.jboss.as.repository] (management-handler-thread - 1) JBAS014900: Content added at location /opt/jboss-eap-6.0/standalone/data/content/29/8df5c9535050d66e2cd5aeaedfdb6fd17330eb/content
10:00:07,457 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "postgresql-9.1-902.jdbc4.jar"
10:00:07,583 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) JBAS010404: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.1)
10:00:07,585 INFO  [org.jboss.as.osgi] (MSC service thread 1-2) JBAS011907: Register module: Module "deployment.postgresql-9.1-902.jdbc4.jar:main" from Service Module Loader
10:00:07,664 INFO  [org.jboss.as.server] (management-handler-thread - 1) JBAS018559: Deployed "postgresql-9.1-902.jdbc4.jar"


第三種,使用網路畫面GUI
這種方式就很簡單拉!按幾個按鈕就可以了!

Step 1, 選擇左邊選單的 Manage Deployments後,選擇右邊的Add Content,這時有個小視窗會跳出來!

Step 2, 按下選擇檔案,選取我們要的JDBC Driver 的jar檔

Step 3, 確認檔案無誤




Step 4, 打開 JDBC Driver, 按下清單中的Enable 即可!


完成畫面


2.Module Drivers 的安裝方式,小妹認為應該是比較適合Production阿,Cluster環境用的,原因它是針對Server 上的安裝,可以domain server 上的安裝!

Step One, 在Module 中建立Driver (因為J老闆的模組都會放在這裡,啓動的時候就會被scan啦!)
      A. 先create 放置 driver 的模組資料夾

      [root@jboss1 modules]# cd org
      [root@jboss1 org]# mkdir postgresql
      [root@jboss1 modules]# cd postgresql
      [root@jboss1 org]# mkdir main


      B. 將 Driver 的 jar 檔放進剛剛建制的資料夾
      [root@jboss1 tmp]# cp postgresql-9.1-902.jdbc4.jar \
      /opt/jboss-eap-6.0/modules/org/postgresql/main/

      C. 建立module.xml 讓J老闆知道這個模組有什麼鬼。

   
<?xml version="1.0" encoding="UTF-8"?>       <module xmlns="urn:jboss:module:1.0" name="com.mysql.jdbc">        <resources>
       <resource-root path="postgresql-9.1-902.jdbc4.jar"/>
       <!-- 如果有多的jar檔,可以放這裡-->
       </resources>        <dependencies>        <module name="javax.api"/>        <module name="javax.transaction.api"/>        </dependencies>       </module>

Step Two, 把Driver 資料放到standalone.xml 裡面註冊。
在 subsystem xmlns="urn:jboss:domain:datasources:1.0" 的中的datasources tag 裡 加上
     
 .....
    <drivers>
        <driver name="h2" module="com.h2database.h2">
            <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
        </driver>
        <driver name="postgres" module="org.postgresql"> 
            <!-- module 就是你在module folder 的 package -->

            <xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
        </driver>
    </drivers>

  .....



Step Three, 這是最簡單的一步! 重開Server! 
之後登入 admin-console 可以看見 postgres 的 Driver 已經 load 進來了!

設定JNDI 連結

新的J老闆有兩種設定的方式,

一種是給技術硬漢,使用文字設定檔案
一種是給喜歡用GUI的人,用最新的Admin Console 設定!

1. 文字設定檔案

<datasource jndi-name="java:jboss/datasource/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
       <connection-url>jdbc:postgresql://172.16.1.79:5432/postgres</connection-url>
        <driver>postgres</driver>
       <security>
               <user-name>postgres</user-name>
               <password>xxxx</password>
        </security>
</datasource>


重新打開Server 後測試connection 成功!




2. 使用GUI 界面的懶人設定法 XD

在左邊的datasource 選單上選擇 Add 的按鈕,輸入Name, 跟 JNDI Name




選擇剛剛設定的Driver



輸入這個資料庫的位置,帳號跟密碼


成功地安裝拉!測試一下,到Connection Tab 按下 Test Connection!這樣就代表成功拉!








Comments

Faith Chen said…


請問
大象資料庫也是設定
name="com.mysql.jdbc"?????

Popular posts from this blog

Red Hat JBoss Fuse/A-MQ - Fuse and A-MQ Version 6.3 GA is released!

Fuse and A-MQ 6.3 GA has just went out. Maybe, you would think this is just only a minor version release why should I care? Hold your thoughts on that! Because they have done a lot of improvements and also added many new features into this release.

Besides various bug fixes and making sure Fuse Fabric is much more stable. There are two major change in this version update:

New Tooling in JBoss Developer Studio (JBDS) 9.1 GA. Newer Apache Camel version – Camel v2.17. I was really impressed by the work put in to make developing Camel application much simpler. First is the installation of tooling itself. Now it has a all-in-one installer so you don't need to worry about which plugins you need to check. See the videos below to see the new "Getting Started" of Fuse 6.3.



And If you notice from the above video, the presentation of camel route in JBDS has also updated. It fixed some of the miss representation of logic and making it easier to read.

Old Camel Route
New Camel Route
On …

Fuse Integration Service - Setup JBDS and create first quickstart application

Before we go and start creating our first application, I want to show you how to setup your JBoss Developer Studio, create a small application from the quickstart example and then running it on Fuse Integration Service.

I am using JBoss Developer Studio version 9, you can find it here.
After download the

jboss-devstudio-9.0.0.GA-installer-eap.jar
double-click it, and start installing with default values.

After successful installation, we will need install the plugins for Fuse, on JBoss Central view, select software update, select enable early access.


And select JBoss Fuse Development for the plugin,


Click on install, and we are all set to go!

First thing first, we want to create a Fuse project to deploy on the base of Fuse Integration Service, which is OpenShift. If you have not installed it, please go back to my previous post for instructions. So on your JBDS, right click and start creating the project. Select new, maven project, if you have installed the plugin correctly, you should …

Red Hat JBoss Fuse - Getting Started with Fuse Integration Service 2.0 Tech preview

I just realized that I did not do a getting started for Fuse Integration Service 2.0 Tech preview before I did the pipeline demo, thanks for those of you who reminded me! :)

To get started with FIS 2.0, for people who has just getting to know the technology, here is how I interpret it. Basically, it's divide into two aspect,

1. Integration development, FIS uses Apache Camel as the core technology that creates, orchestrate, compose microservices into a super lightweight thin integration layer, and become the API provider and service orchestrator through exposing RESTful or messaging service endpoints. And you can choose to either package and run it with Spring-Boot or Karaf.


2. Application Deployment and Management, FIS takes advantages of OpenShift platform, and allows you to separately deploy the micro-integration service among distributed environment, at the same time takes care of the failover, high availability, load balancing and service lookup problem for you.


So, now we know …