WEB开发网
开发学院软件开发Java 任务:消息: 使用一个 Windows 服务来启动 WebSph... 阅读

任务:消息: 使用一个 Windows 服务来启动 WebSphere MQ File Transfer Edition 客户端代理

 2010-10-09 08:13:10 来源:WEB开发网   
核心提示: 结束语MA7K Windows 触发监控器服务是在 Windows 服务器启动时自动启动 WebSphere MQ File Transfer Edition 客户端代理的一个好方法,除了启动代理外,任务:消息: 使用一个 Windows 服务来启动 WebSphere MQ File Tran

结束语

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; 
}

本文示例源代码或素材下载

上一页  4 5 6 7 8 9 

Tags:任务 消息 使用

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接