spring-amqp一个队列多个侦听器

时间:2016-08-11 08:22:17

标签: java spring-amqp spring-rabbit spring-rabbitmq

如何配置接收器以满足以下要求

我有三个任务可以监听单个队列的所有回复" replyQueue"

task1 
task2
task3

每个人都会在Rabbit上发送一条消息,并等待replyQueue上的回复

任务1

     -send message 
        -wait for the responses 
        -There can be multiple responses 
                -status message 1
                -status message 2
                -final message

任务2

-send message 
    -wait for the responses 
    -There can be multiple responses 
            -status message 1
            -status message 2
            -final message

任务3

-send message 
    -wait for the responses 
    -There can be multiple responses 
            -status message 1
            -status message 2
            -final message

现在我必须根据响应做不同的任务。 我如何配置我的队列和听众?

我尝试了以下

template.send("TaskQueue",message);
Message response= template.receive("replyQueue");

但这将允许我只读取一个响应,但我想读取每个任务的多个响应1

请指导。

1 个答案:

答案 0 :(得分:0)

除非我在您的问题中遗漏了某些内容,否则您只需进行多次using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Media3D; using System.Windows.Shapes; namespace Cursoraa2 { class Program : Window { [STAThread] public static void Main() => new Application().Run(new Program()); public Program() { Width = 500; Height = 500; var grid = new Grid(); var viewport = new Viewport3D(); grid.Children.Add(viewport); Content = grid; //RenderOptions.SetEdgeMode(viewport,EdgeMode.Aliased); DynamicCurosr.Start(grid, grid, 40, Color.FromArgb(40, 0x33, 0x33, 0xff), Colors.Blue); MouseMove += MainWindow_MouseMove; MakeBeachBallSphere(viewport); } private void MainWindow_MouseMove(object sender, MouseEventArgs e) => DynamicCurosr.Move(e.GetPosition(this)); public void MakeBeachBallSphere(Viewport3D viewport) { // Get the MeshGeometry3D from the GenerateSphere method. var mesh = GenerateSphere(new Point3D(0, 0, 0), 1, 36, 18); mesh.Freeze(); // Define a brush for the sphere. var brushes = new Brush[6] { Brushes.Red, Brushes.Blue, Brushes.Yellow, Brushes.Orange, Brushes.White, Brushes.Green }; var drawgrp = new DrawingGroup(); for (var i = 0; i < brushes.Length; i++) { var rectgeo = new RectangleGeometry(new Rect(10 * i, 0, 10, 60)); var geodraw = new GeometryDrawing(brushes[i], null, rectgeo); drawgrp.Children.Add(geodraw); } var drawbrsh = new DrawingBrush(drawgrp); drawbrsh.Freeze(); // Define the GeometryModel3D. var geomod = new GeometryModel3D { Geometry = mesh, Material = new DiffuseMaterial(drawbrsh) }; // Create a ModelVisual3D for the GeometryModel3D. var modvis = new ModelVisual3D { Content = geomod }; viewport.Children.Add(modvis); // Create another ModelVisual3D for light. var modgrp = new Model3DGroup(); modgrp.Children.Add(new AmbientLight(Color.FromRgb(128, 128, 128))); modgrp.Children.Add(new DirectionalLight(Color.FromRgb(128, 128, 128), new Vector3D(2, -3, -1))); modvis = new ModelVisual3D {Content = modgrp}; viewport.Children.Add(modvis); // Create the camera. var cam = new PerspectiveCamera(new Point3D(0, 0, 8), new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), 45); viewport.Camera = cam; // Create a transform for the GeometryModel3D. var axisangle = new AxisAngleRotation3D(new Vector3D(1, 1, 0), 180); var rotate = new RotateTransform3D(axisangle); geomod.Transform = rotate; // Animate the RotateTransform3D. //DoubleAnimation anima = new DoubleAnimation(360, new Duration(TimeSpan.FromSeconds(5))); //anima.RepeatBehavior = RepeatBehavior.Forever; //axisangle.BeginAnimation(AxisAngleRotation3D.AngleProperty, anima); } MeshGeometry3D GenerateSphere(Point3D center, double radius, int slices, int stacks) { // Create the MeshGeometry3D. var mesh = new MeshGeometry3D(); // Fill the Position, Normals, and TextureCoordinates collections. for (var stack = 0; stack <= stacks; stack++) { var phi = Math.PI / 2 - stack * Math.PI / stacks; var y = radius * Math.Sin(phi); var scale = -radius * Math.Cos(phi); for (var slice = 0; slice <= slices; slice++) { var theta = slice * 2 * Math.PI / slices; var x = scale * Math.Sin(theta); var z = scale * Math.Cos(theta); var normal = new Vector3D(x, y, z); mesh.Normals.Add(normal); mesh.Positions.Add(normal + center); mesh.TextureCoordinates.Add( new Point((double)slice / slices, (double)stack / stacks)); } } // Fill the TriangleIndices collection. for (var stack = 0; stack < stacks; stack++) for (var slice = 0; slice < slices; slice++) { var n = slices + 1; // Keep the line length down. if (stack != 0) { mesh.TriangleIndices.Add((stack + 0) * n + slice); mesh.TriangleIndices.Add((stack + 1) * n + slice); mesh.TriangleIndices.Add((stack + 0) * n + slice + 1); } if (stack != stacks - 1) { mesh.TriangleIndices.Add((stack + 0) * n + slice + 1); mesh.TriangleIndices.Add((stack + 1) * n + slice); mesh.TriangleIndices.Add((stack + 1) * n + slice + 1); } } return mesh; } } public static class DynamicCurosr { static public bool InSession { get; private set; } private static Panel theCursor; private static readonly ScaleTransform ScaleTransform = new ScaleTransform(1, 1); private static readonly MatrixTransform MatrixTransform = new MatrixTransform(1, 0, 0, 1, 0, 0); private static Color defaultFill = Color.FromArgb(20, 255, 255, 255); private static Color fillFromUser; private static double strokeFromUser = 0; private static Color strokeColorFromUser = Colors.Black; private static int centerDotSizeFromUser = 10; // need to get from user private static double initialDiameter = double.NaN; private static Panel cursorPanel; private static Panel mousePanel; public static bool Start(Panel cursorPanelIn, Panel mousePanelIn, double radius) { return Start(cursorPanelIn, mousePanelIn, radius, defaultFill); } public static bool Start(Panel cursorPanelIn, Panel mousePanelIn, double radius, Color fill, Color strokeColor = default(Color), double strokeSize = .16) { strokeColor = strokeColor == default(Color) ? Colors.Black : strokeColor; strokeColorFromUser = strokeColor; fillFromUser = fill; strokeFromUser = strokeColor == default(Color) ? 0 : strokeSize; initialDiameter = double.IsNaN(initialDiameter) ? radius * 2 : initialDiameter; return Start(cursorPanelIn, mousePanelIn); } private static bool Start(Panel cursorPanelIn, Panel mousePanelIn) { if (InSession) return false; cursorPanel = cursorPanelIn; mousePanel = mousePanelIn; var point = Mouse.GetPosition(cursorPanel); theCursor = MakeACursor(theCursor, initialDiameter / 2); InSession = true; cursorPanel.Cursor = Cursors.None; theCursor.Visibility = Visibility.Visible; Move(point); if (cursorPanel.Children.Contains(theCursor)) return false; cursorPanel.Children.Add(theCursor); Mouse.OverrideCursor = Cursors.None; return true; } public static void Stop() { if (InSession) { Mouse.OverrideCursor = null; theCursor.Visibility = Visibility.Collapsed; cursorPanel.Children.Remove(theCursor); InSession = false; } } public static void Move(Point point) { if (InSession && theCursor.Visibility == Visibility.Visible) { var m = MatrixTransform.Matrix; m.OffsetX = point.X - theCursor.Width / 2; m.OffsetY = point.Y - theCursor.Height / 2; MatrixTransform.Matrix = m; theCursor.RenderTransform = MatrixTransform; } } public static Panel MakeACursor(Panel theCursor, double radius, Color fillColorIn = default(Color), Color strokeColorIn = default(Color)) { var strokeColor = new SolidColorBrush(strokeColorIn == default(Color) ? strokeColorFromUser : strokeColorIn); if (theCursor == null) { theCursor = new Grid() { Width = radius * 2, Height = radius * 2, Background = null, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, RenderTransform = ScaleTransform, RenderTransformOrigin = new Point(.5, .5), }; var cursorElement = new Ellipse { Width = radius * 2, Height = radius * 2, Fill = new SolidColorBrush(fillColorIn == default(Color) ? fillFromUser : fillColorIn), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, StrokeThickness = strokeFromUser, Stroke = strokeColor, RenderTransformOrigin = new Point(.5, .5) }; theCursor.Children.Add(cursorElement); } MakeCursorOverlay(theCursor, radius, strokeColor); return theCursor; } public static void MakeCursorOverlay(Panel theCursor, double radius, SolidColorBrush strokeColor) { var save = theCursor.Children[0]; theCursor.Children.Clear(); theCursor.Children.Add(save); var circle = new Ellipse { Width = centerDotSizeFromUser, Height = centerDotSizeFromUser, Fill = null, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, StrokeThickness = strokeFromUser, Stroke = strokeColor, RenderTransformOrigin = new Point(.5, .5) }; theCursor.Children.Add(circle); } } } 来电。

如果这些任务同时运行,您就不能使用相同的回复队列 - 否则任务将获得彼此的回复 - 在这种情况下,您需要为每个回复队列提供不同的回复队列。