Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link pairing #359

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Examples/PeerToPeer/PeerToPeer.Client/PeerToPeer.Client.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29009.5
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PeerToPeer.Client", "PeerToPeer.Client.csproj", "{A20F24AF-6832-4E04-A941-E3C6F5EC8DBC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A20F24AF-6832-4E04-A941-E3C6F5EC8DBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A20F24AF-6832-4E04-A941-E3C6F5EC8DBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A20F24AF-6832-4E04-A941-E3C6F5EC8DBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A20F24AF-6832-4E04-A941-E3C6F5EC8DBC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {745C8C15-49BB-49D2-9DCD-86B2EA7AD327}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"WARNING01": "*********************************************************************************",
"WARNING02": "The C# extension was unable to automatically decode projects in the current",
"WARNING03": "workspace to create a runnable launch.json file. A template launch.json file has",
"WARNING04": "been created as a placeholder.",
"WARNING05": "",
"WARNING06": "If OmniSharp is currently unable to load your project, you can attempt to resolve",
"WARNING07": "this by restoring any missing project dependencies (example: run 'dotnet restore')",
"WARNING08": "and by fixing any reported errors from building the projects in your workspace.",
"WARNING09": "If this allows OmniSharp to now load your project then --",
"WARNING10": " * Delete this file",
"WARNING11": " * Open the Visual Studio Code command palette (View->Command Palette)",
"WARNING12": " * run the command: '.NET: Generate Assets for Build and Debug'.",
"WARNING13": "",
"WARNING14": "If your project requires a more complex launch configuration, you may wish to delete",
"WARNING15": "this configuration and pick a different template using the 'Add Configuration...'",
"WARNING16": "button at the bottom of this file.",
"WARNING17": "*********************************************************************************",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8FC90E46-024B-4089-9590-A7E8C2B092BE}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PeerToPeer.PairedLinkClient</RootNamespace>
<AssemblyName>PeerToPeer.PairedLinkClient</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IntermediateOutputPath>..\..\..\obj\$(Configuration)\$(MSBuildProjectName)\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\bin\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\bin\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\csproj\Amqp.Net.csproj">
<Project>{92153715-1d99-43b1-b291-470cf91a156d}</Project>
<Name>Amqp.Net</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29009.5
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PeerToPeer.PairedLinkClient", "PeerToPeer.PairedLinkClient.csproj", "{A864BDC8-115E-4CE5-9D99-8FDEED5BD3D1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PeerToPeer.PairedLinkServer", "..\PeerToPeer.PairedLinkServer\PeerToPeer.PairedLinkServer.csproj", "{5E963020-CBBB-48FF-A69D-E10E81448D89}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amqp", "..\..\..\src\Amqp.csproj", "{BC222735-B2D2-4B19-BDA6-C3351E7AB048}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A864BDC8-115E-4CE5-9D99-8FDEED5BD3D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A864BDC8-115E-4CE5-9D99-8FDEED5BD3D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A864BDC8-115E-4CE5-9D99-8FDEED5BD3D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A864BDC8-115E-4CE5-9D99-8FDEED5BD3D1}.Release|Any CPU.Build.0 = Release|Any CPU
{5E963020-CBBB-48FF-A69D-E10E81448D89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E963020-CBBB-48FF-A69D-E10E81448D89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E963020-CBBB-48FF-A69D-E10E81448D89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E963020-CBBB-48FF-A69D-E10E81448D89}.Release|Any CPU.Build.0 = Release|Any CPU
{BC222735-B2D2-4B19-BDA6-C3351E7AB048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC222735-B2D2-4B19-BDA6-C3351E7AB048}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC222735-B2D2-4B19-BDA6-C3351E7AB048}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC222735-B2D2-4B19-BDA6-C3351E7AB048}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EDB34DEA-FF59-4107-9E96-07DB27CB5284}
EndGlobalSection
EndGlobal
135 changes: 135 additions & 0 deletions Examples/PeerToPeer/PeerToPeer.PairedLinkClient/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// ------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the ""License""); you may not use this
// file except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR
// CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR
// NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------------------

using System;
using System.Threading;
using Amqp;
using Amqp.Framing;

namespace PeerToPeer.PairedLinkClient
{
class Program
{
static void Main(string[] args)
{
string address = "amqp://guest:guest@127.0.0.1:5672";
if (args.Length > 0)
{
address = args[0];
}

// uncomment the following to write frame traces
//Trace.TraceLevel = TraceLevel.Frame;
//Trace.TraceListener = (l, f, a) => Console.WriteLine(DateTime.Now.ToString("[hh:mm:ss.fff]") + " " + string.Format(f, a));

Console.WriteLine("Running request client...");
new Client(address).Run();
}

class Client
{
readonly string address;
string replyTo;
Connection connection;
Session session;
int offset;
private InitiatorPairedLink pairedLink;

public Client(string address)
{
this.address = address;
this.replyTo = "client-" + Guid.NewGuid().ToString();
}

public void Run()
{
while (true)
{
try
{
this.Cleanup();
this.Setup();

this.RunOnce();

this.Cleanup();
break;
}
catch (Exception exception)
{
Console.WriteLine("Reconnect on exception: " + exception.Message);

Thread.Sleep(5000);
}
}
}

void Setup()
{
this.connection = new Connection(new Address(address));
this.session = new Session(connection);


var remoteSource = new Source() { Address = "request_processor" };
var remoteTarget = new Target() { Address = "request_processor" };

this.pairedLink =
new InitiatorPairedLink(session, "request-client", remoteTarget, remoteSource);
this.pairedLink.Start(300);
}

void Cleanup()
{
var temp = Interlocked.Exchange(ref this.connection, null);
if (temp != null)
{
temp.Close();
}
}

void RunOnce()
{
Message request = new Message("hello " + this.offset);
request.Properties = new Properties() { MessageId = "command-request", ReplyTo = "$me" };
request.ApplicationProperties = new ApplicationProperties();
request.ApplicationProperties["offset"] = this.offset;
pairedLink.Sender.Send(request, null, null);
Console.WriteLine("Sent request {0} body {1}", request.Properties, request.Body);

while (true)
{
Message response = pairedLink.Receiver.Receive();
if (response != null)
{
pairedLink.Receiver.Accept(response);
Console.WriteLine("Received response: {0} body {1}", response.Properties, response.Body);

if (string.Equals("done", response.Body))
{
break;
}

this.offset = (int) response.ApplicationProperties["offset"];
}
}
}
}
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8FC90E46-024B-4089-9590-A7E8C2B092BE}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PeerToPeer.PairedLinkServer</RootNamespace>
<AssemblyName>PeerToPeer.PairedLinkServer</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IntermediateOutputPath>..\..\..\obj\$(Configuration)\$(MSBuildProjectName)\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\bin\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\bin\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\csproj\Amqp.Net.csproj">
<Project>{92153715-1d99-43b1-b291-470cf91a156d}</Project>
<Name>Amqp.Net</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading