websphere 部署_使用Ant的WebSphere Message Broker部署脚本

websphere 部署

在IBM®WebSphere®Message Broker V6.0.2之前,没有支持使用命令行工具在broker.xml文件中修改可配置属性的方法。 开发人员通常通过使用WebSphere Message Broker工具箱中的Broker Archive Editor或通过手动解压缩Broker Archive(BAR)文件并在Message Broker环境之外操作broker.xml来执行此操作。 在WebSphere Message Broker V6.0.2中,一个名为mqsiapplybaroverride的新命令行工具可以帮助您修改BAR文件中的可配置属性。 本文向您展示了如何使用Ant(流行的基于Java™的开源开源构建工具)从WebSphere Message Broker V6.0.2内部构建和维护BAR文件。 Ant就像Java版本的make。 Ant脚本以XML编写,与make一样,Ant目标可以依赖于其他目标。

BAR文件

BAR文件使您能够将可执行内容部署或动态安装到WebSphere Message Broker域或执行组。 BAR文件是扩展名为.bar而不是.zip的标准ZIP文件。 它类似于用于J2EE部署包装的EAR文件,它们是扩展名为.ear而不是.zip的ZIP文件。 BAR文件包含单个部署描述符(称为broker.xml)以及Java计算节点或ESQL代码中使用的已编译消息流,消息集字典,XML,XSLT和JAR文件。 部署描述符是一个XML文件,存储在BAR文件中的META-INF / broker.xml目录中。 META-INF / broker.xml文件为给定BAR文件中的所有消息流指定可配置属性的替代。 图1显示了broker.xml的XML模式定义:

图1. broker.xml XML模式定义
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="Broker">
    <xsd:annotation>
      <xsd:documentation>
        The document element of the broker.xml file is always a Broker element.
        The structure of the broker.xml file may not be extended or modified by users.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="CompiledMessageFlow" minOccurs="0" maxOccurs="unbounded" />
      </xsd:sequence>
      <xsd:attribute name="name" type="xsd:string" />
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="CompiledMessageFlow">
    <xsd:annotation>
      <xsd:documentation>
        A CompiledMessageFlow element defines all the property overrides
        for a single compiled msgflow ("CMF") file in the root folder of
        the bar archive.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="ConfigurableProperty" minOccurs="0" maxOccurs="unbounded" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="ConfigurableProperty">
    <xsd:annotation>
      <xsd:documentation>
        A ConfigurableProperty optionally specifies a deploy-time
        value for a single configurable property.

        Attribute "uri" specifies the broker-schema qualified flow name,
        the node name (if needed),and the property name. Uri is required.

        Attribute "override" specifies the value to assign to the
        property during installation.

        Override is optional. If override is not set, the configurable
        property value at install defaults to the value in the flow.
        If override is set (even to ""), the value of the configurable
        property at install is set to the value of override.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:attribute ref="uri" use="required" />
      <xsd:attribute ref="override" use="optional" />
    </xsd:complexType>
  </xsd:element>

  <xsd:attribute name="uri" type="xsd:string">
    <xsd:annotation>
      <xsd:documentation>
  The following specifies the syntax for uri attribute values in the
  broker.xml ConfigurableProperty elements.

  URI
  >>--+-------------------+--flowName-- # --+---------------+--propertyName-->>
      +--schemaName-- . --+                 +--nodeName-- . --+

 where:
 * "schemaName" is the name of the Broker schema the msgflow was defined in,
                or nothing if the msgflow is defined in the unnamed schema.
                schemaName is a dot separated list of path segments.
 * "flowName"   is the name of the msgflow; i.e. the name of the file without
                the .msgflow or .msgnode extension.
 * "nodeName"   is the label of the node, if the property is defined on a node.
                The nodeName parameter is optional, and does not appear if the
                property is defined on a flow.
  * propertyName is the name of the property, or the label key if the node is
                a primitive node. The descriptor tab of the BAR editor displays
                the NL enabled name if the label key matches a NL enabled name,
                else it displays the key itself.
      </xsd:documentation>
    </xsd:annotation>
  </xsd:attribute>

  <xsd:attribute name="override" type="xsd:string">
    <xsd:annotation>
      <xsd:documentation>
  Override is an optional attribute. If the attribute is absent, the
  default value set in the msgflow tool will be applied at install time.
  If a value is provided for override, then that value will be applied
  at install time. If override="", then the value at install time is the
  empty string.
      </xsd:documentation>
    </xsd:annotation>
  </xsd:attribute>
</xsd:schema>

使用Ant创建BAR文件

Ant是用于自动化构建环境的强大工具。 从Ant任务中调用mqsicreatebar是从消息流和消息集源工件构建BAR文件的常用方法。 从源文件构建BAR文件的最常见方法是使用Ant脚本从存储库中提取源数据,尽管您不必为了使用mqsicreatebar命令而使用此技术。 这是mqsicreatebar命令的语法图, WebSphere Message Broker信息中心也对此进行了描述:

图2. mqsicreatebar命令的语法图
>>-mqsicreatebar-- -data --WorkSpace-- -b --BarName------------->

>--+--------------+--+---------------------------+-------------->
   '- -cleanBuild-'  '- -version --VersionString-'

                 .-----------------------.
                 V                       |
>--+----------+----+-------------------+-+-- -o ---------------->
   '- -Esql21-'    '- -p --ProjectName-'

   .--------------.
   V              |
>------FilePath---+--------------------------------------------><

参量

-data 工作台
(必需)在其中创建项目的工作空间的路径。
-b BarName
(必需)存储结果的BAR文件的名称。 如果BAR文件已经存在并且替换了BAR文件中的META-INF / broker.xml文件,它将被替换。
-cleanBuild
(可选)刷新工作空间中的项目,然后在将新项目添加到BAR文件之前调用一个干净的版本。 如果使用外部工具对BAR文件资源进行了修改,请使用-cleanBuild参数刷新BAR文件中的所有项目,并调用一个干净的版本。
版本VersionString
(可选)在文件扩展名之前,将_(下划线)字符和VersionString的值附加到添加到BAR文件的对象的名称上。 在Message Broker V6.0中,引入了运行时版本控制,您应该使用该机制对源文件进行版本控制并将其传播到已部署的执行组。 有关详细信息,请参阅WebSphere Message Broker信息中心
-Esql21
(可选)为V2.1代理编译ESQL。
-p 项目名称
(可选)项目包含要包含在BAR文件中的文件。 您可以指定多个项目,其中可以包括消息流项目,消息集项目或消息流插件节点项目。 如果您指定的项目不属于工作空间,则该命令会将项目链接到工作空间,以便该项目中的文件可以包含在BAR文件中。 该命令不会将文件复制到您的工作区目录中。 如果您指定的项目是工作空间的一部分但已关闭,则该命令将打开并生成该项目,以便该项目中的文件可以包含在BAR文件中。
-o FilePath
(必需)要添加到BAR文件中的msgflow或messageSet.mset文件的工作区相对路径(包括项目)。 您可以使用以下格式向该命令添加多个可部署文件:-o FilePath1 FilePath2 .... FilePath'n'。

在现有工作空间和新工作空间中使用-data

mqsicreatebar命令的-data参数引用工作空间目录,其行为取决于工作空间目录是否已存在。

如果工作空间和.metadata目录已经存在并且已经包含Message Set和Message Flow项目,则-p选项不是必需的。 但是,无论工作空间目录是否已存在,都应始终提供-p选项。 如果确实存在,那么如果在WebSphere Message Broker工具箱之外更改了任何文件,则发出-cleanBuild参数。 -cleanBuild选项强制刷新给定工作空间内的所有项目。 然后发出-cleanBuild以使项目与现有.metadata信息同步。

如果工作空间目录不存在,则-p选项是必需的,因此可以将其指定的项目添加到新创建的工作空间中。 在这种情况下,-cleanBuild参数不是必需的,因为将项目添加到新的工作区时,-p选项将强制对它们进行干净的构建。 当-data引用使用Ant使用mqsicreatebar构建BAR文件时不存在的工作空间时,请使用第二个选项,因为消息流和消息集项目通常是从存储库中提取的,并且源文件将与将使用的工作空间。 这将需要“ -cleanBuild”参数,并且可能给出不一致的结果。 您可以通过提供正确的参数从任何Ant任务中调用mqsicreatebar命令。 下面的图3显示了一个示例Ant任务,它将构建一个给定的BAR文件:

图3.示例ant任务,调用mqsicreatebar命令来构建BAR文件
<?xml version="1.0"?>
<project name="project" default="run">
  <target name="run" description="">
    <property name="toolkit.home" value="C:\MessageBroker\602" />
    <property name="ant.bars.basedir" value="C:\Dev\messagebroker" />
    <property name="workspaces.dir" value="${ant.bars.basedir}\workspace" />
    <property name="bar.name" value="${ant.bars.basedir}\postcard.bar" />
    <antcall target="mqsicreatebar.buildbar" />
  </target>

  <!--
    Target to build the broker archive using mqsicreatebar
  -->
  <target name="mqsicreatebar.buildbar">
    <echo message="Building Broker Archive file: ${bar.name} " />
    <exec executable="${toolkit.home}\eclipse\mqsicreatebar.exe" spawn="false">
      <arg value="-data" />
      <arg value="${workspaces.dir}" />
      <arg value="-b" />
      <arg value="${bar.name}" />
      <arg value="-p" />
      <arg value="Postcard" />
      <arg value="PostcardFlow" />
      <arg value="-o" />
      <arg value="Postcard\Postcard\messageSet.mset" />
      <arg value="PostcardFlow\PostcardFlow.msgflow" />
    </exec>
    <echo message="Completed building Broker Archive file - ${bar.name} " />
  </target>
</project>

使用Ant修改BAR文件部署描述符

使用mqsiapplybaroverride命令可将BAR文件部署描述符中的可配置值替换为在属性文件中指定的新值。 您可以将此命令与mqsicreatebar命令结合使用。 下面的图4是mqsiapplybaroverride命令的语法图,该消息WebSphere Message Broker信息中心中也有描述。

图4. mqsiapplybaroverride命令的语法图
>>-mqsiapplybaroverride-- -b --BarFile-- -p --PropertiesFile---><

参量

-b BarFile
(必需)适用覆盖值的BAR文件的路径(绝对路径或相对于可执行命令的路径)。
-p 属性文件
(必需)包含替代值的属性文件的路径(绝对或相对于可执行命令)。

mqsiapplyoverride命令可以更改broker.xml文件中的特定URI,或替换BAR文件broker.xml文件中的特定替代值的所有实例。

下面的图5显示了使用图6中的属性值应用mqsiapplyoverride命令之前,给定BAR文件中的broker.xml文件。图7然后显示了给定BAR文件中具有更新值的新broker.xml文件。 更改的两个可配置属性是:

<ConfigurableProperty uri="PostcardFlow#additionalInstances" />
<ConfigurableProperty override="Q1" uri="PostcardFlow#MQInput.queueName" />
图5.在应用新的覆盖值之前,BAR文件中的样本broker.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<Broker>
  <CompiledMessageFlow name="PostcardFlow">
    <ConfigurableProperty uri="PostcardFlow#additionalInstances" />
    <ConfigurableProperty uri="PostcardFlow#commitCount" />
    <ConfigurableProperty uri="PostcardFlow#commitInterval" />
    <ConfigurableProperty uri="PostcardFlow#coordinatedTransaction" />
    <ConfigurableProperty uri="PostcardFlow#MQInput.serializationToken" />
    <ConfigurableProperty uri="PostcardFlow#MQInput.topicProperty" />
    <ConfigurableProperty uri="PostcardFlow#Postcard.validateMaster" />
    <ConfigurableProperty uri="PostcardFlow#MQOutput.queueManagerName" />
    <ConfigurableProperty uri="PostcardFlow#MQOutput.replyToQMgr" />
    <ConfigurableProperty uri="PostcardFlow#Postcard.dataSource" />
    <ConfigurableProperty uri="PostcardFlow#MQOutput.replyToQ" />
    <ConfigurableProperty uri="PostcardFlow#MQInput.validateMaster" />
    <ConfigurableProperty uri="PostcardFlow#MQOutput.validateMaster" />
    <ConfigurableProperty override="Q1" uri="PostcardFlow#MQInput.queueName" />
    <ConfigurableProperty uri="PostcardFlow#MQOutput.queueName" />
  </CompiledMessageFlow>
</Broker>
图6.传递给mqsiapplyoverride命令中-p选项的示例属性文件
#If want to replace a specific URI override value within the broker.xml
#URI_<uri with # escaped with a backslash \>=<new override value>
URI_PostcardFlow\#additionalInstances=2

#Replace all places in broker.xml that have IQ as a override value with
<old override value>=<new override value>
Q1=TEST_QUEUE
图7.应用新的覆盖值之后,BAR文件中的样本broker.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<Broker>
  <CompiledMessageFlow name="PostcardFlow">
   <ConfigurableProperty override="2" uri="PostcardFlow#additionalInstances" />
    <ConfigurableProperty uri="PostcardFlow#commitCount" />
    <ConfigurableProperty uri="PostcardFlow#commitInterval" />
    <ConfigurableProperty uri="PostcardFlow#coordinatedTransaction" />
    <ConfigurableProperty uri="PostcardFlow#MQInput.serializationToken" />
    <ConfigurableProperty uri="PostcardFlow#MQInput.topicProperty" />
    <ConfigurableProperty uri="PostcardFlow#Postcard.validateMaster" />
    <ConfigurableProperty uri="PostcardFlow#MQOutput.queueManagerName" />
    <ConfigurableProperty uri="PostcardFlow#MQOutput.replyToQMgr" />
    <ConfigurableProperty uri="PostcardFlow#Postcard.dataSource" />
    <ConfigurableProperty uri="PostcardFlow#MQOutput.replyToQ" />
    <ConfigurableProperty uri="PostcardFlow#MQInput.validateMaster" />
    <ConfigurableProperty uri="PostcardFlow#MQOutput.validateMaster" />
   <ConfigurableProperty override="TEST_QUEUE" 
			uri="PostcardFlow#MQInput.queueName" />
    <ConfigurableProperty uri="PostcardFlow#MQOutput.queueName" />
  </CompiledMessageFlow>
</Broker>

您可以通过提供正确的参数从任何Ant任务中调用mqsiapplybaroverride命令。 下面的图8显示了一个示例Ant任务,它将更改给定BAR文件中的替代值:

图8.示例Ant任务,调用mqsiapplybaroverride命令来修改BAR文件部署描述符
<?xml version="1.0"?>
<project name="project" default="run">
  <target name="run" description="">
    <property name="toolkit.home" value="C:\MessageBroker\602" />
    <property name="ant.bars.basedir" value="C:\Dev\messagebroker" />
    <property name="bar.name" value="${ant.bars.basedir}\postcard.bar" />
    <property name="bar.properties.name" 
			value="${ant.bars.basedir}\brokerxml.properties" />

    <antcall target="mqsiapplybaroverride.modifybar" />
  </target>

  <!--
    Target to build the broker archive using mqsiapplybaroverride
  -->
  <target name="mqsiapplybaroverride.modifybar">
    <echo message="Applying overrides in Broker Archive file - ${bar.name} " />
    <echo
      message="${toolkit.home}\eclipse\mqsiapplybaroverride.exe 
			  -b  ${bar.name} -p ${bar.properties.name}" />
    <exec executable="${toolkit.home}\eclipse\mqsiapplybaroverride.exe" spawn="false">
      <arg value="-b" />
      <arg value="${bar.name}" />
      <arg value="-p" />
      <arg value="${bar.properties.name}" />
    </exec>
    <echo message="Completed apply overrides in Broker Archive file - ${bar.name}" />
  </target>
</project>

结论

本文向您展示了如何使用Ant脚本语言通过WebSphere Message Broker V6.0.2命令行工具自动构建BAR文件的脚本过程,从而减少了人工干预并避免了构建BAR文件时的常见错误。 使用Ant脚本构建BAR文件提供了一种一致且可靠的方式来修改其中的部署描述符。


翻译自: https://www.ibm.com/developerworks/websphere/library/techarticles/0706_spriet/0706_spriet.html

websphere 部署

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值