2011年7月21日 星期四

[JMS] MessageListener.onMessage

A client can register an object that implements the JMS MessageListener interface with a MessageConsumer. As messages arrive for the consumer, the provider delivers them by calling the listener’s onMessage method.

It is possible for a listener to throw a RuntimeException; however, this is considered a client programming error. Well-behaved listeners should catch such exceptions and attempt to divert messages causing them to some form of application-specific ‘unprocessable message’ destination.

The result of a listener throwing a RuntimeException depends on the session’s acknowledgment mode.

AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE - the message will be immediately redelivered. The number of times a JMS provider will redeliver the same message before giving up is provider-dependent. The JMSRedelivered message header field will be set for a message redelivered under these circumstances.
CLIENT_ACKNOWLEDGE - the next message for the listener is delivered. If a client wishes to have the previous unacknowledged message redelivered, it must manually recover the session.
Transacted Session - the next message for the listener is delivered. The client can either commit or roll back the session (in other words, a RuntimeException does not automatically rollback the session).

JMS providers should flag clients with message listeners that are throwing RuntimeExceptions as possibly malfunctioning.

2011年7月5日 星期二

[MySQL] 手動安裝

1. 註冊為系統Service:
    mysqld --install MySQL3 --defaults-file="%CURRENT_DIR%\my-huge.ini"
2. 從系統Service中移除:
    mysqld --remove MySQL3
3. 啟動Service:
    net start MySQL3
4. 關閉Service:
    net stop MySQL3

2011年5月15日 星期日

[C#] byte[] to hex format string

            StringBuilder sb = new StringBuilder(byteData.Length * 2);
            foreach (byte b in byteData)
            {
                sb.AppendFormat("{0:x2}", b);
            }

2011年5月2日 星期一

[C#] log4net 設定檔變數

  %m(message):輸出的日志消息,如ILog.Debug(…)輸出的一條消息
  %n(new line):換行
  %d(datetime):輸出當前语句運行的時刻
  %r(run time):輸出程序從運行到執行到當前語句時消耗的毫秒數
  %t(thread id):當前語句所在的線程ID
  %p(priority): 日志的當前優先級别,即DEBUG、INFO、WARN…等
  %c(class):當前日志對象的名稱
  %L:輸出語句所在的行號
  %F:輸出語句所在的文件名
  %-數字:表示該項的最小長度,如果不夠,則用空格填充

2011年3月2日 星期三

[C#] Thread 執行的method接受參數

1. 要給thread執行的method要能傳入參數Object
public static void StartClient(object messageObj) 
2. 在呼叫Thread.Start()時, 傳入參數
Thread thread = new Thread(AsynchronousClient.StartClient);
thread.Start("456, 121.54068, 25.047867, 0");

2011年2月20日 星期日

[C#] using


using 關鍵字有兩個用途:
1. 作為指令,用於為命名空間創建別名或導入其他命名空間中定義的類型。
2. 作為語句,用於定義一個範圍,在此範圍的末尾將釋放物件。
與try/catch/finally共同點: 都可以釋放資源 
與try/catch/finally不同點:
try/catch/finally可以用來捕獲異常並處理, using不行 
using可以創建別名,導入命名空間 ,try catch finally不行 
using會在資源超出範圍後主動釋放物件,try catch finally要程式師自己寫 釋放物件 的代碼