任务:消息: 使用一个 Windows 服务来启动 WebSphere MQ File Transfer Edition 客户端代理
2010-10-09 08:13:10 来源:WEB开发网结束语
MA7K Windows 触发监控器服务是在 Windows 服务器启动时自动启动 WebSphere MQ File Transfer Edition 客户端代理的一个好方法。除了启动代理外,触发监控器将在代理关闭或从命令队列断开连接时重新启动代理。如果触发监控器设置为自动重新启动,则整个配置将变得非常有弹性。此服务还有一个额外的好处,触发 WebSphere MQ File Transfer Edition 代理允许 WebSphere MQ 管理员通过在代理的命令队列上启用和禁用代理来启动和停止它。
清单 3. fteTriggerAgent.pl
#----------------------------------------------------------------------#
# fteTriggerAgent.pl
#
# Windows program to start a triggered FTE agent
#
# Script parses a WMQ TMC2 tigger message and starts the named FTE agent
# specified in the process definition. Uses unpack so that the MQSeries
# Perl module is not required.
#
# The command constructed from the process definition is as follows:
# Drive:\path to\fteStartAgent AgentName
#
# The $EnvData contains the fully-qualified executable name which must
# end with fteStartAgent.cmd
#
# The $UserData field must contain the agent name.
#
#
#----------------------------------------------------------------------#
# History
# 20100125 T.Rob - New script
#
#
#----------------------------------------------------------------------#
use strict;
use Fcntl qw(:flock);
use File::Path 'mkpath';
$| = 1; # Turn on Autoflush
($0) = (split(m|[/\\]|, $0))[-1]; # Normalize $0
my $Testing = 1; # Set to 0 to disable dump of trigger messages
my $LogFile;
# Set up the log file name
{
my ($Min, $Hr, $MDay, $Mon, $Year) = (localtime(time))[1..5];
$Year = $Year %100; $Mon++;
my $TimeStamp = sprintf("%02d%02d%02d",$Year,$Mon,$MDay);
my $LogPath = 'C:\\IBM\\WMQFTE\\Logs';
my @Created = mkpath( $LogPath );
$LogFile = "$LogPath\\$0.$TimeStamp.log";
}
# Trigger Message struct tagMQTMC2 {
my ($StrucId, # MQCHAR4 StrucId; /* Structure identifier */
$Version, # MQCHAR4 Version; /* Structure version number*/
$QName, # MQCHAR48 QName; /* Name of triggered queue */
$ProcessName, # MQCHAR48 ProcessName; /* Name of process object */
$TriggerData, # MQCHAR64 TriggerData; /* Trigger data */
$ApplType, # MQCHAR4 ApplType; /* Application type */
$ApplId, # MQCHAR256 ApplId; /* Application identifier */
$EnvData, # MQCHAR128 EnvData; /* Environment data */
$UserData, # MQCHAR128 UserData; /* User data */
$QMgrName, # MQCHAR48 QMgrName; /* Queue manager name */
); # };
&Log("$0 Started", exists($ENV{'COMPUTERNAME'}) ? " on $ENV{'COMPUTERNAME'}" : '');
foreach (@ARGV) {
if (/^TMC 2/) { # Ignore all parms but TMC2 itself
($StrucId, $Version, $QName, $ProcessName, $TriggerData, $ApplType,
$ApplId, $EnvData, $UserData, $QMgrName,)
= unpack("a4 a4 a48 a48 a64 a4 a256 a128 a128 a48", $_);
$QName =~ s/\s+$//; # delete trailing spaces
$ApplId =~ s/\s+$//; # delete trailing spaces
$UserData =~ s/\s+$//; # delete trailing spaces
$EnvData =~ s/\s+$//; # delete trailing spaces
$QMgrName =~ s/\s+$//; # delete trailing spaces
&DumpTriggerMsg if $Testing;
# Verify the $EnvData parm
my $Path;
if ($EnvData =~ /^(.*)\\bin\\fteStartAgent.cmd$/ && -e $EnvData) {
$Path = $1;
} else {
&Log("$0: Bad command in process ENVRDATA: '$EnvData'");
}
my @Exec = ($EnvData, $UserData);
&Log(join(" ", @Exec), "\n");
system(@Exec);
last;
} else {
if (/^-v/i) {
$Testing = 1;
&Log("Verbose mode enabled on command line.");
} else {
&Log("Parm not a TMC2 message = '$_'");
}
}
}
&Log("$0 Ended.\n\n");
exit 1; # Non-zero exit for trigger monitor
sub DumpTriggerMsg {
&Log("\$0 = '$0");
&Log("StrucId = '$StrucId'");
&Log("Version = '$Version'");
&Log("QName = '$QName'");
&Log("ProcessName = '$ProcessName'");
&Log("TriggerData = '$TriggerData'");
&Log("ApplType = '$ApplType'");
&Log("ApplId = '$ApplId'");
&Log("EnvData = '$EnvData'");
&Log("UserData = '$UserData'");
&Log("QMgrName = '$QMgrName'\n");
}
sub Log {
my ($Sec, $Min, $Hr, $MDay, $Mon, $Year) = (localtime(time))[0..5];
my $TimeStamp = sprintf("%04d%02d%02d-%02d:%02d:%02d: ",($Year+1900),
++$Mon,$MDay,$Hr,$Min,$Sec);
open LOG, ">>$LogFile";
# Wait up to 5 seconds for an exclusive lock on log file, else skip logging
my $Sleep = 5;
while ($Sleep) {
# Non-Blocking check for an exclusive lock
if (flock(LOG, LOCK_EX|LOCK_NB)) {
print LOG $TimeStamp, @_, "\n";
$Sleep = 0;
} else {
--$Sleep;
}
}
close LOG;
}
本文示例源代码或素材下载
- ››使用脚本恢复WinXP系统的用户登录密码
- ››使用phpMyadmin创建数据库及独立数据库帐号
- ››使用Zend Framework框架中的Zend_Mail模块发送邮件...
- ››使用cout标准输出如何控制小数点后位数
- ››使用nofollow标签做SEO的技巧
- ››使用 WebSphere Message Broker 的 WebSphere Tra...
- ››使用SQL Server事件探查器做应用程序的性能分析
- ››使用SQL Server事件探查器分析死锁原因
- ››消息称中国移动即将获得iPhone 4销售权
- ››使用纯文本文件打造WCF服务
- ››任务:消息: 使用一个 Windows 服务来启动 WebSph...
- ››使用 Dojo 开发定制 Business Space 小部件,第 4...
更多精彩
赞助商链接